moneta 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.travis.yml +39 -0
- data/Gemfile +61 -0
- data/LICENSE +2 -2
- data/README.md +450 -0
- data/Rakefile +29 -51
- data/SPEC.md +75 -0
- data/benchmarks/run.rb +195 -0
- data/lib/action_dispatch/middleware/session/moneta_store.rb +11 -0
- data/lib/active_support/cache/moneta_store.rb +55 -0
- data/lib/moneta.rb +121 -67
- data/lib/moneta/adapters/activerecord.rb +87 -0
- data/lib/moneta/adapters/cassandra.rb +91 -0
- data/lib/moneta/adapters/client.rb +69 -0
- data/lib/moneta/adapters/cookie.rb +35 -0
- data/lib/moneta/adapters/couch.rb +57 -0
- data/lib/moneta/adapters/datamapper.rb +75 -0
- data/lib/moneta/adapters/dbm.rb +25 -0
- data/lib/moneta/adapters/file.rb +79 -0
- data/lib/moneta/adapters/fog.rb +51 -0
- data/lib/moneta/adapters/gdbm.rb +25 -0
- data/lib/moneta/adapters/hbase.rb +101 -0
- data/lib/moneta/adapters/leveldb.rb +35 -0
- data/lib/moneta/adapters/localmemcache.rb +28 -0
- data/lib/moneta/adapters/lruhash.rb +85 -0
- data/lib/moneta/adapters/memcached.rb +11 -0
- data/lib/moneta/adapters/memcached_dalli.rb +69 -0
- data/lib/moneta/adapters/memcached_native.rb +70 -0
- data/lib/moneta/adapters/memory.rb +10 -0
- data/lib/moneta/adapters/mongo.rb +50 -0
- data/lib/moneta/adapters/null.rb +30 -0
- data/lib/moneta/adapters/pstore.rb +69 -0
- data/lib/moneta/adapters/redis.rb +68 -0
- data/lib/moneta/adapters/riak.rb +57 -0
- data/lib/moneta/adapters/sdbm.rb +35 -0
- data/lib/moneta/adapters/sequel.rb +79 -0
- data/lib/moneta/adapters/sqlite.rb +65 -0
- data/lib/moneta/adapters/tokyocabinet.rb +41 -0
- data/lib/moneta/adapters/yaml.rb +15 -0
- data/lib/moneta/base.rb +78 -0
- data/lib/moneta/builder.rb +39 -0
- data/lib/moneta/cache.rb +84 -0
- data/lib/moneta/expires.rb +71 -0
- data/lib/moneta/lock.rb +25 -0
- data/lib/moneta/logger.rb +61 -0
- data/lib/moneta/mixins.rb +65 -0
- data/lib/moneta/net.rb +18 -0
- data/lib/moneta/optionmerger.rb +39 -0
- data/lib/moneta/proxy.rb +86 -0
- data/lib/moneta/server.rb +81 -0
- data/lib/moneta/shared.rb +60 -0
- data/lib/moneta/stack.rb +78 -0
- data/lib/moneta/transformer.rb +159 -0
- data/lib/moneta/transformer/config.rb +42 -0
- data/lib/moneta/transformer/helper.rb +37 -0
- data/lib/moneta/version.rb +5 -0
- data/lib/moneta/wrapper.rb +33 -0
- data/lib/rack/cache/moneta.rb +93 -0
- data/lib/rack/moneta_cookies.rb +64 -0
- data/lib/rack/session/moneta.rb +63 -0
- data/moneta.gemspec +19 -0
- data/spec/action_dispatch/fixtures/session_autoload_test/foo.rb +10 -0
- data/spec/action_dispatch/session_moneta_store_spec.rb +196 -0
- data/spec/active_support/cache_moneta_store_spec.rb +197 -0
- data/spec/generate.rb +1489 -0
- data/spec/helper.rb +91 -0
- data/spec/moneta/adapter_activerecord_spec.rb +32 -0
- data/spec/moneta/adapter_cassandra_spec.rb +30 -0
- data/spec/moneta/adapter_client_spec.rb +19 -0
- data/spec/moneta/adapter_cookie_spec.rb +18 -0
- data/spec/moneta/adapter_couch_spec.rb +18 -0
- data/spec/moneta/adapter_datamapper_spec.rb +49 -0
- data/spec/moneta/adapter_dbm_spec.rb +18 -0
- data/spec/moneta/adapter_file_spec.rb +18 -0
- data/spec/moneta/adapter_fog_spec.rb +23 -0
- data/spec/moneta/adapter_gdbm_spec.rb +18 -0
- data/spec/moneta/adapter_hbase_spec.rb +18 -0
- data/spec/moneta/adapter_leveldb_spec.rb +18 -0
- data/spec/moneta/adapter_localmemcache_spec.rb +18 -0
- data/spec/moneta/adapter_lruhash_spec.rb +31 -0
- data/spec/moneta/adapter_memcached_dalli_spec.rb +30 -0
- data/spec/moneta/adapter_memcached_native_spec.rb +31 -0
- data/spec/moneta/adapter_memcached_spec.rb +30 -0
- data/spec/moneta/adapter_memory_spec.rb +39 -0
- data/spec/moneta/adapter_mongo_spec.rb +18 -0
- data/spec/moneta/adapter_pstore_spec.rb +21 -0
- data/spec/moneta/adapter_redis_spec.rb +30 -0
- data/spec/moneta/adapter_riak_spec.rb +22 -0
- data/spec/moneta/adapter_sdbm_spec.rb +18 -0
- data/spec/moneta/adapter_sequel_spec.rb +18 -0
- data/spec/moneta/adapter_sqlite_spec.rb +18 -0
- data/spec/moneta/adapter_tokyocabinet_bdb_spec.rb +18 -0
- data/spec/moneta/adapter_tokyocabinet_hdb_spec.rb +18 -0
- data/spec/moneta/adapter_yaml_spec.rb +21 -0
- data/spec/moneta/cache_file_memory_spec.rb +34 -0
- data/spec/moneta/cache_memory_null_spec.rb +23 -0
- data/spec/moneta/expires_file_spec.rb +76 -0
- data/spec/moneta/expires_memory_spec.rb +65 -0
- data/spec/moneta/lock_spec.rb +42 -0
- data/spec/moneta/null_adapter_spec.rb +26 -0
- data/spec/moneta/optionmerger_spec.rb +92 -0
- data/spec/moneta/proxy_expires_memory_spec.rb +55 -0
- data/spec/moneta/proxy_redis_spec.rb +23 -0
- data/spec/moneta/shared_spec.rb +30 -0
- data/spec/moneta/simple_activerecord_spec.rb +51 -0
- data/spec/moneta/simple_activerecord_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_cassandra_spec.rb +52 -0
- data/spec/moneta/simple_client_tcp_spec.rb +67 -0
- data/spec/moneta/simple_client_unix_spec.rb +53 -0
- data/spec/moneta/simple_couch_spec.rb +51 -0
- data/spec/moneta/simple_couch_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_datamapper_spec.rb +53 -0
- data/spec/moneta/simple_datamapper_with_expires_spec.rb +54 -0
- data/spec/moneta/simple_datamapper_with_repository_spec.rb +53 -0
- data/spec/moneta/simple_dbm_spec.rb +51 -0
- data/spec/moneta/simple_dbm_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_file_spec.rb +51 -0
- data/spec/moneta/simple_file_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_fog_spec.rb +56 -0
- data/spec/moneta/simple_fog_with_expires_spec.rb +58 -0
- data/spec/moneta/simple_gdbm_spec.rb +51 -0
- data/spec/moneta/simple_gdbm_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_hashfile_spec.rb +51 -0
- data/spec/moneta/simple_hashfile_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_hbase_spec.rb +51 -0
- data/spec/moneta/simple_hbase_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_leveldb_spec.rb +51 -0
- data/spec/moneta/simple_leveldb_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_localmemcache_spec.rb +51 -0
- data/spec/moneta/simple_localmemcache_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_lruhash_spec.rb +51 -0
- data/spec/moneta/simple_lruhash_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_memcached_dalli_spec.rb +52 -0
- data/spec/moneta/simple_memcached_native_spec.rb +52 -0
- data/spec/moneta/simple_memcached_spec.rb +52 -0
- data/spec/moneta/simple_memory_spec.rb +51 -0
- data/spec/moneta/simple_memory_with_compress_spec.rb +51 -0
- data/spec/moneta/simple_memory_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_memory_with_json_key_serializer_spec.rb +37 -0
- data/spec/moneta/simple_memory_with_json_serializer_spec.rb +28 -0
- data/spec/moneta/simple_memory_with_json_value_serializer_spec.rb +35 -0
- data/spec/moneta/simple_memory_with_prefix_spec.rb +51 -0
- data/spec/moneta/simple_memory_with_snappy_compress_spec.rb +51 -0
- data/spec/moneta/simple_mongo_spec.rb +51 -0
- data/spec/moneta/simple_mongo_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_null_spec.rb +36 -0
- data/spec/moneta/simple_pstore_spec.rb +51 -0
- data/spec/moneta/simple_pstore_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_redis_spec.rb +52 -0
- data/spec/moneta/simple_riak_spec.rb +55 -0
- data/spec/moneta/simple_riak_with_expires_spec.rb +56 -0
- data/spec/moneta/simple_sdbm_spec.rb +51 -0
- data/spec/moneta/simple_sdbm_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_sequel_spec.rb +51 -0
- data/spec/moneta/simple_sequel_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_sqlite_spec.rb +51 -0
- data/spec/moneta/simple_sqlite_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_tokyocabinet_spec.rb +51 -0
- data/spec/moneta/simple_tokyocabinet_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_yaml_spec.rb +50 -0
- data/spec/moneta/simple_yaml_with_expires_spec.rb +51 -0
- data/spec/moneta/stack_file_memory_spec.rb +25 -0
- data/spec/moneta/stack_memory_file_spec.rb +24 -0
- data/spec/moneta/transformer_bencode_spec.rb +30 -0
- data/spec/moneta/transformer_bert_spec.rb +30 -0
- data/spec/moneta/transformer_bson_spec.rb +30 -0
- data/spec/moneta/transformer_bzip2_spec.rb +27 -0
- data/spec/moneta/transformer_json_spec.rb +30 -0
- data/spec/moneta/transformer_lzma_spec.rb +27 -0
- data/spec/moneta/transformer_lzo_spec.rb +27 -0
- data/spec/moneta/transformer_marshal_base64_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_escape_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_hmac_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_md5_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_md5_spread_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_prefix_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_rmd160_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_sha1_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_sha256_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_sha384_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_sha512_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_truncate_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_uuencode_spec.rb +54 -0
- data/spec/moneta/transformer_msgpack_spec.rb +30 -0
- data/spec/moneta/transformer_ox_spec.rb +51 -0
- data/spec/moneta/transformer_quicklz_spec.rb +27 -0
- data/spec/moneta/transformer_snappy_spec.rb +27 -0
- data/spec/moneta/transformer_tnet_spec.rb +30 -0
- data/spec/moneta/transformer_yaml_spec.rb +51 -0
- data/spec/moneta/transformer_zlib_spec.rb +27 -0
- data/spec/monetaspecs.rb +2663 -0
- data/spec/rack/cache_moneta_spec.rb +355 -0
- data/spec/rack/moneta_cookies_spec.rb +81 -0
- data/spec/rack/session_moneta_spec.rb +305 -0
- metadata +359 -56
- data/README +0 -51
- data/TODO +0 -4
- data/lib/moneta/basic_file.rb +0 -111
- data/lib/moneta/berkeley.rb +0 -53
- data/lib/moneta/couch.rb +0 -63
- data/lib/moneta/datamapper.rb +0 -117
- data/lib/moneta/file.rb +0 -91
- data/lib/moneta/lmc.rb +0 -52
- data/lib/moneta/memcache.rb +0 -52
- data/lib/moneta/memory.rb +0 -11
- data/lib/moneta/mongodb.rb +0 -58
- data/lib/moneta/redis.rb +0 -49
- data/lib/moneta/rufus.rb +0 -41
- data/lib/moneta/s3.rb +0 -162
- data/lib/moneta/sdbm.rb +0 -33
- data/lib/moneta/tyrant.rb +0 -58
- data/lib/moneta/xattr.rb +0 -58
data/TODO
DELETED
data/lib/moneta/basic_file.rb
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Basic File Store
|
3
|
-
# by Hampton Catlin
|
4
|
-
#
|
5
|
-
# This cache simply uses a directory that it creates
|
6
|
-
# and manages to keep your file stores.
|
7
|
-
#
|
8
|
-
# Specify :skip_expires => true if you aren't using
|
9
|
-
# expiration as this will slightly decrease your file size
|
10
|
-
# and memory footprint of the library
|
11
|
-
#
|
12
|
-
# You can optionally also specify a :namespace
|
13
|
-
# option that will create a subfolder.
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
require 'fileutils'
|
18
|
-
require File.join(File.dirname(__FILE__), "..", "moneta.rb")
|
19
|
-
|
20
|
-
module Moneta
|
21
|
-
class BasicFile
|
22
|
-
include Defaults
|
23
|
-
|
24
|
-
def initialize(options = {})
|
25
|
-
@namespace = options[:namespace]
|
26
|
-
@directory = ::File.join(options[:path], @namespace.to_s)
|
27
|
-
|
28
|
-
@expires = !options[:skip_expires]
|
29
|
-
|
30
|
-
ensure_directory_created(@directory)
|
31
|
-
end
|
32
|
-
|
33
|
-
def key?(key)
|
34
|
-
!self[key].nil?
|
35
|
-
end
|
36
|
-
|
37
|
-
alias has_key? key?
|
38
|
-
|
39
|
-
def [](key)
|
40
|
-
if ::File.exist?(path(key))
|
41
|
-
data = raw_get(key)
|
42
|
-
if @expires
|
43
|
-
if data[:expires_at].nil? || data[:expires_at] > Time.now
|
44
|
-
data[:value]
|
45
|
-
else
|
46
|
-
delete!(key)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def raw_get(key)
|
53
|
-
Marshal.load(::File.read(path(key)))
|
54
|
-
end
|
55
|
-
|
56
|
-
def []=(key, value)
|
57
|
-
store(key, value)
|
58
|
-
end
|
59
|
-
|
60
|
-
def store(key, value, options = {})
|
61
|
-
ensure_directory_created(::File.dirname(path(key)))
|
62
|
-
::File.open(path(key), "w") do |file|
|
63
|
-
if @expires
|
64
|
-
data = {:value => value}
|
65
|
-
if options[:expires_in]
|
66
|
-
data[:expires_at] = Time.now + options[:expires_in]
|
67
|
-
end
|
68
|
-
contents = Marshal.dump(data)
|
69
|
-
else
|
70
|
-
contents = Marshal.dump(value)
|
71
|
-
end
|
72
|
-
file.puts(contents)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def update_key(key, options)
|
77
|
-
store(key, self[key], options)
|
78
|
-
end
|
79
|
-
|
80
|
-
def delete!(key)
|
81
|
-
FileUtils.rm(path(key))
|
82
|
-
nil
|
83
|
-
rescue Errno::ENOENT
|
84
|
-
end
|
85
|
-
|
86
|
-
def delete(key)
|
87
|
-
value = self[key]
|
88
|
-
delete!(key)
|
89
|
-
value
|
90
|
-
end
|
91
|
-
|
92
|
-
def clear
|
93
|
-
FileUtils.rm_rf(@directory)
|
94
|
-
FileUtils.mkdir(@directory)
|
95
|
-
end
|
96
|
-
|
97
|
-
private
|
98
|
-
def path(key)
|
99
|
-
::File.join(@directory, key.to_s)
|
100
|
-
end
|
101
|
-
|
102
|
-
def ensure_directory_created(directory_path)
|
103
|
-
if ::File.file?(directory_path)
|
104
|
-
raise StandardError, "The path you supplied #{directory_path} is a file"
|
105
|
-
elsif !::File.exists?(directory_path)
|
106
|
-
FileUtils.mkdir_p(directory_path)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
111
|
-
end
|
data/lib/moneta/berkeley.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'bdb'
|
3
|
-
rescue LoadError
|
4
|
-
puts "You need bdb gem to use Bdb moneta store"
|
5
|
-
exit
|
6
|
-
end
|
7
|
-
|
8
|
-
module Moneta
|
9
|
-
|
10
|
-
class Berkeley
|
11
|
-
include Defaults
|
12
|
-
|
13
|
-
def initialize(options={})
|
14
|
-
file = @file = options[:file]
|
15
|
-
@db = Bdb::Db.new()
|
16
|
-
@db.open(nil, file, nil, Bdb::Db::BTREE, Bdb::DB_CREATE, 0)
|
17
|
-
unless options[:skip_expires]
|
18
|
-
@expiration = Moneta::Berkeley.new(:file => "#{file}_expiration", :skip_expires => true )
|
19
|
-
self.extend(StringExpires)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
module Implementation
|
24
|
-
def key?(key)
|
25
|
-
nil | self[key]
|
26
|
-
end
|
27
|
-
|
28
|
-
alias has_key? key?
|
29
|
-
|
30
|
-
def []=(key,value)
|
31
|
-
@db[key] = value
|
32
|
-
end
|
33
|
-
|
34
|
-
def [](key)
|
35
|
-
@db[key]
|
36
|
-
end
|
37
|
-
|
38
|
-
def delete(key)
|
39
|
-
value = self[key]
|
40
|
-
@db.del(nil,key,0) if value
|
41
|
-
value
|
42
|
-
end
|
43
|
-
|
44
|
-
def clear
|
45
|
-
@db.truncate(nil)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
include Implementation
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
data/lib/moneta/couch.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require "couchrest"
|
3
|
-
rescue LoadError
|
4
|
-
puts "You need the couchrest gem to use the CouchDB store"
|
5
|
-
exit
|
6
|
-
end
|
7
|
-
|
8
|
-
module Moneta
|
9
|
-
class Couch
|
10
|
-
include Defaults
|
11
|
-
|
12
|
-
def initialize(options = {})
|
13
|
-
@db = ::CouchRest.database!(options[:db])
|
14
|
-
unless options[:skip_expires]
|
15
|
-
@expiration = Moneta::Couch.new(:db => "#{options[:db]}_expiration", :skip_expires => true)
|
16
|
-
self.extend(StringExpires)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def key?(key)
|
21
|
-
!self[key].nil?
|
22
|
-
rescue RestClient::ResourceNotFound
|
23
|
-
false
|
24
|
-
end
|
25
|
-
|
26
|
-
alias has_key? key?
|
27
|
-
|
28
|
-
def [](key)
|
29
|
-
@db.get(key)["data"]
|
30
|
-
rescue RestClient::ResourceNotFound
|
31
|
-
nil
|
32
|
-
end
|
33
|
-
|
34
|
-
def []=(key, value)
|
35
|
-
@db.save_doc("_id" => key, :data => value)
|
36
|
-
rescue RestClient::RequestFailed
|
37
|
-
self[key]
|
38
|
-
end
|
39
|
-
|
40
|
-
def delete(key)
|
41
|
-
value = @db.get(key)
|
42
|
-
@db.delete_doc({"_id" => value["_id"], "_rev" => value["_rev"]}) if value
|
43
|
-
value["data"]
|
44
|
-
rescue RestClient::ResourceNotFound
|
45
|
-
nil
|
46
|
-
end
|
47
|
-
|
48
|
-
def update_key(key, options = {})
|
49
|
-
val = self[key]
|
50
|
-
self.store(key, val, options)
|
51
|
-
rescue RestClient::ResourceNotFound
|
52
|
-
nil
|
53
|
-
end
|
54
|
-
|
55
|
-
def clear
|
56
|
-
@db.recreate!
|
57
|
-
end
|
58
|
-
|
59
|
-
def delete_store
|
60
|
-
@db.delete!
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
data/lib/moneta/datamapper.rb
DELETED
@@ -1,117 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
gem "dm-core", "0.9.10"
|
3
|
-
require "dm-core"
|
4
|
-
rescue LoadError
|
5
|
-
puts "You need the dm-core gem in order to use the DataMapper moneta store"
|
6
|
-
exit
|
7
|
-
end
|
8
|
-
|
9
|
-
class MonetaHash
|
10
|
-
include DataMapper::Resource
|
11
|
-
|
12
|
-
property :the_key, String, :key => true
|
13
|
-
property :value, Object, :lazy => false
|
14
|
-
property :expires, Time
|
15
|
-
|
16
|
-
def self.value(key)
|
17
|
-
obj = self.get(key)
|
18
|
-
obj && obj.value
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
module Moneta
|
23
|
-
class DataMapper
|
24
|
-
class Expiration
|
25
|
-
def initialize(klass, repository)
|
26
|
-
@klass = klass
|
27
|
-
@repository = repository
|
28
|
-
end
|
29
|
-
|
30
|
-
def [](key)
|
31
|
-
if obj = get(key)
|
32
|
-
obj.expires
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def []=(key, value)
|
37
|
-
obj = get(key)
|
38
|
-
obj.expires = value
|
39
|
-
obj.save(@repository)
|
40
|
-
end
|
41
|
-
|
42
|
-
def delete(key)
|
43
|
-
obj = get(key)
|
44
|
-
obj.expires = nil
|
45
|
-
obj.save(@repository)
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
def get(key)
|
50
|
-
repository(@repository) { @klass.get(key) }
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def initialize(options = {})
|
55
|
-
@repository = options.delete(:repository) || :moneta
|
56
|
-
::DataMapper.setup(@repository, options[:setup])
|
57
|
-
repository_context { MonetaHash.auto_upgrade! }
|
58
|
-
@hash = MonetaHash
|
59
|
-
@expiration = Expiration.new(MonetaHash, @repository)
|
60
|
-
end
|
61
|
-
|
62
|
-
module Implementation
|
63
|
-
def key?(key)
|
64
|
-
repository_context { !!@hash.get(key) }
|
65
|
-
end
|
66
|
-
|
67
|
-
def has_key?(key)
|
68
|
-
repository_context { !!@hash.get(key) }
|
69
|
-
end
|
70
|
-
|
71
|
-
def [](key)
|
72
|
-
repository_context { @hash.value(key) }
|
73
|
-
end
|
74
|
-
|
75
|
-
def []=(key, value)
|
76
|
-
repository_context {
|
77
|
-
obj = @hash.get(key)
|
78
|
-
if obj
|
79
|
-
obj.update(key, value)
|
80
|
-
else
|
81
|
-
@hash.create(:the_key => key, :value => value)
|
82
|
-
end
|
83
|
-
}
|
84
|
-
end
|
85
|
-
|
86
|
-
def fetch(key, value = nil)
|
87
|
-
repository_context {
|
88
|
-
value ||= block_given? ? yield(key) : default
|
89
|
-
self[key] || value
|
90
|
-
}
|
91
|
-
end
|
92
|
-
|
93
|
-
def delete(key)
|
94
|
-
repository_context {
|
95
|
-
value = self[key]
|
96
|
-
@hash.all(:the_key => key).destroy!
|
97
|
-
value
|
98
|
-
}
|
99
|
-
end
|
100
|
-
|
101
|
-
def store(key, value, options = {})
|
102
|
-
repository_context { self[key] = value }
|
103
|
-
end
|
104
|
-
|
105
|
-
def clear
|
106
|
-
repository_context { @hash.all.destroy! }
|
107
|
-
end
|
108
|
-
|
109
|
-
private
|
110
|
-
def repository_context
|
111
|
-
repository(@repository) { yield }
|
112
|
-
end
|
113
|
-
end
|
114
|
-
include Implementation
|
115
|
-
include Expires
|
116
|
-
end
|
117
|
-
end
|
data/lib/moneta/file.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require "xattr"
|
3
|
-
rescue LoadError
|
4
|
-
puts "You need the xattr gem to use the File moneta store"
|
5
|
-
exit
|
6
|
-
end
|
7
|
-
require "fileutils"
|
8
|
-
|
9
|
-
module Moneta
|
10
|
-
class File
|
11
|
-
class Expiration
|
12
|
-
def initialize(directory)
|
13
|
-
@directory = directory
|
14
|
-
end
|
15
|
-
|
16
|
-
def [](key)
|
17
|
-
attrs = xattr(key)
|
18
|
-
ret = Marshal.load(attrs.get("moneta_expires"))
|
19
|
-
rescue Errno::ENOENT, SystemCallError
|
20
|
-
end
|
21
|
-
|
22
|
-
def []=(key, value)
|
23
|
-
attrs = xattr(key)
|
24
|
-
attrs.set("moneta_expires", Marshal.dump(value))
|
25
|
-
end
|
26
|
-
|
27
|
-
def delete(key)
|
28
|
-
attrs = xattr(key)
|
29
|
-
attrs.remove("moneta_expires")
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
def xattr(key)
|
34
|
-
::Xattr.new(::File.join(@directory, key))
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def initialize(options = {})
|
39
|
-
@directory = options[:path]
|
40
|
-
if ::File.file?(@directory)
|
41
|
-
raise StandardError, "The path you supplied #{@directory} is a file"
|
42
|
-
elsif !::File.exists?(@directory)
|
43
|
-
FileUtils.mkdir_p(@directory)
|
44
|
-
end
|
45
|
-
|
46
|
-
@expiration = Expiration.new(@directory)
|
47
|
-
end
|
48
|
-
|
49
|
-
module Implementation
|
50
|
-
def key?(key)
|
51
|
-
::File.exist?(path(key))
|
52
|
-
end
|
53
|
-
|
54
|
-
alias has_key? key?
|
55
|
-
|
56
|
-
def [](key)
|
57
|
-
if ::File.exist?(path(key))
|
58
|
-
Marshal.load(::File.read(path(key)))
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def []=(key, value)
|
63
|
-
::File.open(path(key), "w") do |file|
|
64
|
-
contents = Marshal.dump(value)
|
65
|
-
file.puts(contents)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def delete(key)
|
70
|
-
value = self[key]
|
71
|
-
FileUtils.rm(path(key))
|
72
|
-
value
|
73
|
-
rescue Errno::ENOENT
|
74
|
-
end
|
75
|
-
|
76
|
-
def clear
|
77
|
-
FileUtils.rm_rf(@directory)
|
78
|
-
FileUtils.mkdir(@directory)
|
79
|
-
end
|
80
|
-
|
81
|
-
private
|
82
|
-
def path(key)
|
83
|
-
::File.join(@directory, key.to_s)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
include Implementation
|
87
|
-
include Defaults
|
88
|
-
include Expires
|
89
|
-
|
90
|
-
end
|
91
|
-
end
|
data/lib/moneta/lmc.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require "localmemcache"
|
3
|
-
rescue LoadError
|
4
|
-
puts "You need the localmemcache gem to use the LMC moneta store"
|
5
|
-
exit
|
6
|
-
end
|
7
|
-
|
8
|
-
module Moneta
|
9
|
-
class Expiration
|
10
|
-
def initialize(hash)
|
11
|
-
@hash = hash
|
12
|
-
end
|
13
|
-
|
14
|
-
def [](key) @hash["#{key}__!__expiration"] end
|
15
|
-
def []=(key, value) @hash["#{key}__!__expiration"] = value end
|
16
|
-
|
17
|
-
def delete(key)
|
18
|
-
key = "#{key}__!__expiration"
|
19
|
-
value = @hash[key]
|
20
|
-
@hash.delete(key)
|
21
|
-
value
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class LMC
|
26
|
-
include Defaults
|
27
|
-
|
28
|
-
module Implementation
|
29
|
-
def initialize(options = {})
|
30
|
-
@hash = LocalMemCache.new(:filename => options[:filename])
|
31
|
-
@expiration = Expiration.new(@hash)
|
32
|
-
end
|
33
|
-
|
34
|
-
def [](key) @hash[key] end
|
35
|
-
def []=(key, value) @hash[key] = value end
|
36
|
-
def clear() @hash.clear end
|
37
|
-
|
38
|
-
def key?(key)
|
39
|
-
@hash.keys.include?(key)
|
40
|
-
end
|
41
|
-
|
42
|
-
def delete(key)
|
43
|
-
value = @hash[key]
|
44
|
-
@hash.delete(key)
|
45
|
-
value
|
46
|
-
end
|
47
|
-
end
|
48
|
-
include Implementation
|
49
|
-
include StringExpires
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|