Skip to content

Commit

Permalink
Merge commit 'hiddenbek/master'
Browse files Browse the repository at this point in the history
* commit 'hiddenbek/master':
  Return value from Moneta::Expires#store rather than timestamp
  Added SDBM store.  Appears faster than file or xattr, and has no dependencies.
  Added SBDM store.  Appears to be faster than file or xattr.  No dependencies.
  • Loading branch information
wycats committed Apr 10, 2009
2 parents d2b8373 + d0dd04d commit 43b2f5f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/moneta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def update_key(key, options)
end

def store(key, value, options = {})
super(key, value)
update_options(key, options)
super(key, value)
end

private
Expand Down
40 changes: 40 additions & 0 deletions lib/moneta/sdbm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require "sdbm"

module Moneta
class BasicSDBM < ::SDBM

def [](key)
if val = super
Marshal.load(val)
end
end

def []=(key, value)
super(key, Marshal.dump(value))
end

def fetch(key, default)
self[key] || default
end

def store(key, value, options = {})
self[key] = value
end

def delete(key)
if val = super
Marshal.load(val)
end
end
end

class SDBM < BasicSDBM
include Expires

def initialize(options = {})
raise "No :file option specified" unless file = options[:file]
@expiration = BasicSDBM.new("#{file}_expires")
super(file)
end
end
end
17 changes: 17 additions & 0 deletions spec/moneta_sdbm_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require File.dirname(__FILE__) + '/spec_helper'
require "moneta/sdbm"

describe "Moneta::SDBM" do
before(:each) do
@cache = Moneta::SDBM.new(:file => File.join(File.dirname(__FILE__), "sdbm_cache"))
@cache.clear
end

after(:all) do
FileUtils.rm_rf(Dir.glob(File.join(File.dirname(__FILE__), "sdbm_cache*")))
end

if ENV['MONETA_TEST'].nil? || ENV['MONETA_TEST'] == 'sdbm'
it_should_behave_like "a read/write Moneta cache"
end
end

0 comments on commit 43b2f5f

Please sign in to comment.