forked from wycats/moneta
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
3 changed files
with
58 additions
and
1 deletion.
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
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,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 |
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,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 |