Skip to content
Browse files

Merge commit 'hiddenbek/master'

* 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...
2 parents d2b8373 + d0dd04d commit 43b2f5fcbe684ef2ad7001059b3b45821115d8a7 @wycats wycats committed
Showing with 58 additions and 1 deletion.
  1. +1 −1 lib/moneta.rb
  2. +40 −0 lib/moneta/sdbm.rb
  3. +17 −0 spec/moneta_sdbm_spec.rb
View
2 lib/moneta.rb
@@ -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
View
40 lib/moneta/sdbm.rb
@@ -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
View
17 spec/moneta_sdbm_spec.rb
@@ -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.
Something went wrong with that request. Please try again.