Skip to content

Commit

Permalink
Add support for mmap (LMC) adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed May 9, 2009
1 parent ddd47c5 commit 7162af5
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
52 changes: 52 additions & 0 deletions lib/moneta/lmc.rb
@@ -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
24 changes: 24 additions & 0 deletions spec/moneta_lmc_spec.rb
@@ -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

0 comments on commit 7162af5

Please sign in to comment.