forked from wycats/moneta
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
begin | ||
require "localmemcache" | ||
rescue LoadError | ||
puts "You need the localmemcache gem to use the LMC moneta store" | ||
exit | ||
end | ||
|
||
module Moneta | ||
class Expiration | ||
def initialize(hash) | ||
@hash = hash | ||
end | ||
|
||
def [](key) @hash["#{key}__!__expiration"] end | ||
def []=(key, value) @hash["#{key}__!__expiration"] = value end | ||
|
||
def delete(key) | ||
key = "#{key}__!__expiration" | ||
value = @hash[key] | ||
@hash.delete(key) | ||
value | ||
end | ||
end | ||
|
||
class LMC | ||
include Defaults | ||
|
||
module Implementation | ||
def initialize(options = {}) | ||
@hash = LocalMemCache.new(:filename => options[:filename]) | ||
@expiration = Expiration.new(@hash) | ||
end | ||
|
||
def [](key) @hash[key] end | ||
def []=(key, value) @hash[key] = value end | ||
def clear() @hash.clear end | ||
|
||
def key?(key) | ||
@hash.keys.include?(key) | ||
end | ||
|
||
def delete(key) | ||
value = @hash[key] | ||
@hash.delete(key) | ||
value | ||
end | ||
end | ||
include Implementation | ||
include StringExpires | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require File.dirname(__FILE__) + '/spec_helper' | ||
|
||
begin | ||
require "moneta/lmc" | ||
require "fileutils" | ||
|
||
# Problem: If there are multiple caches around, they start | ||
# to block (with a system semaphore), which can be unpleasant | ||
# so just use one cache for the entire test run. | ||
$lmc_cache = Moneta::LMC.new(:filename => "test") | ||
|
||
describe "Moneta::LMC" do | ||
before(:all) do | ||
@cache = $lmc_cache | ||
end | ||
|
||
after(:each) do | ||
@cache.clear | ||
end | ||
|
||
it_should_behave_like "a read/write Moneta cache" | ||
end | ||
rescue SystemExit | ||
end |