moneta 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. data/.gitignore +7 -0
  2. data/.travis.yml +39 -0
  3. data/Gemfile +61 -0
  4. data/LICENSE +2 -2
  5. data/README.md +450 -0
  6. data/Rakefile +29 -51
  7. data/SPEC.md +75 -0
  8. data/benchmarks/run.rb +195 -0
  9. data/lib/action_dispatch/middleware/session/moneta_store.rb +11 -0
  10. data/lib/active_support/cache/moneta_store.rb +55 -0
  11. data/lib/moneta.rb +121 -67
  12. data/lib/moneta/adapters/activerecord.rb +87 -0
  13. data/lib/moneta/adapters/cassandra.rb +91 -0
  14. data/lib/moneta/adapters/client.rb +69 -0
  15. data/lib/moneta/adapters/cookie.rb +35 -0
  16. data/lib/moneta/adapters/couch.rb +57 -0
  17. data/lib/moneta/adapters/datamapper.rb +75 -0
  18. data/lib/moneta/adapters/dbm.rb +25 -0
  19. data/lib/moneta/adapters/file.rb +79 -0
  20. data/lib/moneta/adapters/fog.rb +51 -0
  21. data/lib/moneta/adapters/gdbm.rb +25 -0
  22. data/lib/moneta/adapters/hbase.rb +101 -0
  23. data/lib/moneta/adapters/leveldb.rb +35 -0
  24. data/lib/moneta/adapters/localmemcache.rb +28 -0
  25. data/lib/moneta/adapters/lruhash.rb +85 -0
  26. data/lib/moneta/adapters/memcached.rb +11 -0
  27. data/lib/moneta/adapters/memcached_dalli.rb +69 -0
  28. data/lib/moneta/adapters/memcached_native.rb +70 -0
  29. data/lib/moneta/adapters/memory.rb +10 -0
  30. data/lib/moneta/adapters/mongo.rb +50 -0
  31. data/lib/moneta/adapters/null.rb +30 -0
  32. data/lib/moneta/adapters/pstore.rb +69 -0
  33. data/lib/moneta/adapters/redis.rb +68 -0
  34. data/lib/moneta/adapters/riak.rb +57 -0
  35. data/lib/moneta/adapters/sdbm.rb +35 -0
  36. data/lib/moneta/adapters/sequel.rb +79 -0
  37. data/lib/moneta/adapters/sqlite.rb +65 -0
  38. data/lib/moneta/adapters/tokyocabinet.rb +41 -0
  39. data/lib/moneta/adapters/yaml.rb +15 -0
  40. data/lib/moneta/base.rb +78 -0
  41. data/lib/moneta/builder.rb +39 -0
  42. data/lib/moneta/cache.rb +84 -0
  43. data/lib/moneta/expires.rb +71 -0
  44. data/lib/moneta/lock.rb +25 -0
  45. data/lib/moneta/logger.rb +61 -0
  46. data/lib/moneta/mixins.rb +65 -0
  47. data/lib/moneta/net.rb +18 -0
  48. data/lib/moneta/optionmerger.rb +39 -0
  49. data/lib/moneta/proxy.rb +86 -0
  50. data/lib/moneta/server.rb +81 -0
  51. data/lib/moneta/shared.rb +60 -0
  52. data/lib/moneta/stack.rb +78 -0
  53. data/lib/moneta/transformer.rb +159 -0
  54. data/lib/moneta/transformer/config.rb +42 -0
  55. data/lib/moneta/transformer/helper.rb +37 -0
  56. data/lib/moneta/version.rb +5 -0
  57. data/lib/moneta/wrapper.rb +33 -0
  58. data/lib/rack/cache/moneta.rb +93 -0
  59. data/lib/rack/moneta_cookies.rb +64 -0
  60. data/lib/rack/session/moneta.rb +63 -0
  61. data/moneta.gemspec +19 -0
  62. data/spec/action_dispatch/fixtures/session_autoload_test/foo.rb +10 -0
  63. data/spec/action_dispatch/session_moneta_store_spec.rb +196 -0
  64. data/spec/active_support/cache_moneta_store_spec.rb +197 -0
  65. data/spec/generate.rb +1489 -0
  66. data/spec/helper.rb +91 -0
  67. data/spec/moneta/adapter_activerecord_spec.rb +32 -0
  68. data/spec/moneta/adapter_cassandra_spec.rb +30 -0
  69. data/spec/moneta/adapter_client_spec.rb +19 -0
  70. data/spec/moneta/adapter_cookie_spec.rb +18 -0
  71. data/spec/moneta/adapter_couch_spec.rb +18 -0
  72. data/spec/moneta/adapter_datamapper_spec.rb +49 -0
  73. data/spec/moneta/adapter_dbm_spec.rb +18 -0
  74. data/spec/moneta/adapter_file_spec.rb +18 -0
  75. data/spec/moneta/adapter_fog_spec.rb +23 -0
  76. data/spec/moneta/adapter_gdbm_spec.rb +18 -0
  77. data/spec/moneta/adapter_hbase_spec.rb +18 -0
  78. data/spec/moneta/adapter_leveldb_spec.rb +18 -0
  79. data/spec/moneta/adapter_localmemcache_spec.rb +18 -0
  80. data/spec/moneta/adapter_lruhash_spec.rb +31 -0
  81. data/spec/moneta/adapter_memcached_dalli_spec.rb +30 -0
  82. data/spec/moneta/adapter_memcached_native_spec.rb +31 -0
  83. data/spec/moneta/adapter_memcached_spec.rb +30 -0
  84. data/spec/moneta/adapter_memory_spec.rb +39 -0
  85. data/spec/moneta/adapter_mongo_spec.rb +18 -0
  86. data/spec/moneta/adapter_pstore_spec.rb +21 -0
  87. data/spec/moneta/adapter_redis_spec.rb +30 -0
  88. data/spec/moneta/adapter_riak_spec.rb +22 -0
  89. data/spec/moneta/adapter_sdbm_spec.rb +18 -0
  90. data/spec/moneta/adapter_sequel_spec.rb +18 -0
  91. data/spec/moneta/adapter_sqlite_spec.rb +18 -0
  92. data/spec/moneta/adapter_tokyocabinet_bdb_spec.rb +18 -0
  93. data/spec/moneta/adapter_tokyocabinet_hdb_spec.rb +18 -0
  94. data/spec/moneta/adapter_yaml_spec.rb +21 -0
  95. data/spec/moneta/cache_file_memory_spec.rb +34 -0
  96. data/spec/moneta/cache_memory_null_spec.rb +23 -0
  97. data/spec/moneta/expires_file_spec.rb +76 -0
  98. data/spec/moneta/expires_memory_spec.rb +65 -0
  99. data/spec/moneta/lock_spec.rb +42 -0
  100. data/spec/moneta/null_adapter_spec.rb +26 -0
  101. data/spec/moneta/optionmerger_spec.rb +92 -0
  102. data/spec/moneta/proxy_expires_memory_spec.rb +55 -0
  103. data/spec/moneta/proxy_redis_spec.rb +23 -0
  104. data/spec/moneta/shared_spec.rb +30 -0
  105. data/spec/moneta/simple_activerecord_spec.rb +51 -0
  106. data/spec/moneta/simple_activerecord_with_expires_spec.rb +52 -0
  107. data/spec/moneta/simple_cassandra_spec.rb +52 -0
  108. data/spec/moneta/simple_client_tcp_spec.rb +67 -0
  109. data/spec/moneta/simple_client_unix_spec.rb +53 -0
  110. data/spec/moneta/simple_couch_spec.rb +51 -0
  111. data/spec/moneta/simple_couch_with_expires_spec.rb +52 -0
  112. data/spec/moneta/simple_datamapper_spec.rb +53 -0
  113. data/spec/moneta/simple_datamapper_with_expires_spec.rb +54 -0
  114. data/spec/moneta/simple_datamapper_with_repository_spec.rb +53 -0
  115. data/spec/moneta/simple_dbm_spec.rb +51 -0
  116. data/spec/moneta/simple_dbm_with_expires_spec.rb +52 -0
  117. data/spec/moneta/simple_file_spec.rb +51 -0
  118. data/spec/moneta/simple_file_with_expires_spec.rb +52 -0
  119. data/spec/moneta/simple_fog_spec.rb +56 -0
  120. data/spec/moneta/simple_fog_with_expires_spec.rb +58 -0
  121. data/spec/moneta/simple_gdbm_spec.rb +51 -0
  122. data/spec/moneta/simple_gdbm_with_expires_spec.rb +52 -0
  123. data/spec/moneta/simple_hashfile_spec.rb +51 -0
  124. data/spec/moneta/simple_hashfile_with_expires_spec.rb +52 -0
  125. data/spec/moneta/simple_hbase_spec.rb +51 -0
  126. data/spec/moneta/simple_hbase_with_expires_spec.rb +52 -0
  127. data/spec/moneta/simple_leveldb_spec.rb +51 -0
  128. data/spec/moneta/simple_leveldb_with_expires_spec.rb +52 -0
  129. data/spec/moneta/simple_localmemcache_spec.rb +51 -0
  130. data/spec/moneta/simple_localmemcache_with_expires_spec.rb +52 -0
  131. data/spec/moneta/simple_lruhash_spec.rb +51 -0
  132. data/spec/moneta/simple_lruhash_with_expires_spec.rb +52 -0
  133. data/spec/moneta/simple_memcached_dalli_spec.rb +52 -0
  134. data/spec/moneta/simple_memcached_native_spec.rb +52 -0
  135. data/spec/moneta/simple_memcached_spec.rb +52 -0
  136. data/spec/moneta/simple_memory_spec.rb +51 -0
  137. data/spec/moneta/simple_memory_with_compress_spec.rb +51 -0
  138. data/spec/moneta/simple_memory_with_expires_spec.rb +52 -0
  139. data/spec/moneta/simple_memory_with_json_key_serializer_spec.rb +37 -0
  140. data/spec/moneta/simple_memory_with_json_serializer_spec.rb +28 -0
  141. data/spec/moneta/simple_memory_with_json_value_serializer_spec.rb +35 -0
  142. data/spec/moneta/simple_memory_with_prefix_spec.rb +51 -0
  143. data/spec/moneta/simple_memory_with_snappy_compress_spec.rb +51 -0
  144. data/spec/moneta/simple_mongo_spec.rb +51 -0
  145. data/spec/moneta/simple_mongo_with_expires_spec.rb +52 -0
  146. data/spec/moneta/simple_null_spec.rb +36 -0
  147. data/spec/moneta/simple_pstore_spec.rb +51 -0
  148. data/spec/moneta/simple_pstore_with_expires_spec.rb +52 -0
  149. data/spec/moneta/simple_redis_spec.rb +52 -0
  150. data/spec/moneta/simple_riak_spec.rb +55 -0
  151. data/spec/moneta/simple_riak_with_expires_spec.rb +56 -0
  152. data/spec/moneta/simple_sdbm_spec.rb +51 -0
  153. data/spec/moneta/simple_sdbm_with_expires_spec.rb +52 -0
  154. data/spec/moneta/simple_sequel_spec.rb +51 -0
  155. data/spec/moneta/simple_sequel_with_expires_spec.rb +52 -0
  156. data/spec/moneta/simple_sqlite_spec.rb +51 -0
  157. data/spec/moneta/simple_sqlite_with_expires_spec.rb +52 -0
  158. data/spec/moneta/simple_tokyocabinet_spec.rb +51 -0
  159. data/spec/moneta/simple_tokyocabinet_with_expires_spec.rb +52 -0
  160. data/spec/moneta/simple_yaml_spec.rb +50 -0
  161. data/spec/moneta/simple_yaml_with_expires_spec.rb +51 -0
  162. data/spec/moneta/stack_file_memory_spec.rb +25 -0
  163. data/spec/moneta/stack_memory_file_spec.rb +24 -0
  164. data/spec/moneta/transformer_bencode_spec.rb +30 -0
  165. data/spec/moneta/transformer_bert_spec.rb +30 -0
  166. data/spec/moneta/transformer_bson_spec.rb +30 -0
  167. data/spec/moneta/transformer_bzip2_spec.rb +27 -0
  168. data/spec/moneta/transformer_json_spec.rb +30 -0
  169. data/spec/moneta/transformer_lzma_spec.rb +27 -0
  170. data/spec/moneta/transformer_lzo_spec.rb +27 -0
  171. data/spec/moneta/transformer_marshal_base64_spec.rb +54 -0
  172. data/spec/moneta/transformer_marshal_escape_spec.rb +54 -0
  173. data/spec/moneta/transformer_marshal_hmac_spec.rb +54 -0
  174. data/spec/moneta/transformer_marshal_md5_spec.rb +54 -0
  175. data/spec/moneta/transformer_marshal_md5_spread_spec.rb +54 -0
  176. data/spec/moneta/transformer_marshal_prefix_spec.rb +54 -0
  177. data/spec/moneta/transformer_marshal_rmd160_spec.rb +54 -0
  178. data/spec/moneta/transformer_marshal_sha1_spec.rb +54 -0
  179. data/spec/moneta/transformer_marshal_sha256_spec.rb +54 -0
  180. data/spec/moneta/transformer_marshal_sha384_spec.rb +54 -0
  181. data/spec/moneta/transformer_marshal_sha512_spec.rb +54 -0
  182. data/spec/moneta/transformer_marshal_truncate_spec.rb +54 -0
  183. data/spec/moneta/transformer_marshal_uuencode_spec.rb +54 -0
  184. data/spec/moneta/transformer_msgpack_spec.rb +30 -0
  185. data/spec/moneta/transformer_ox_spec.rb +51 -0
  186. data/spec/moneta/transformer_quicklz_spec.rb +27 -0
  187. data/spec/moneta/transformer_snappy_spec.rb +27 -0
  188. data/spec/moneta/transformer_tnet_spec.rb +30 -0
  189. data/spec/moneta/transformer_yaml_spec.rb +51 -0
  190. data/spec/moneta/transformer_zlib_spec.rb +27 -0
  191. data/spec/monetaspecs.rb +2663 -0
  192. data/spec/rack/cache_moneta_spec.rb +355 -0
  193. data/spec/rack/moneta_cookies_spec.rb +81 -0
  194. data/spec/rack/session_moneta_spec.rb +305 -0
  195. metadata +359 -56
  196. data/README +0 -51
  197. data/TODO +0 -4
  198. data/lib/moneta/basic_file.rb +0 -111
  199. data/lib/moneta/berkeley.rb +0 -53
  200. data/lib/moneta/couch.rb +0 -63
  201. data/lib/moneta/datamapper.rb +0 -117
  202. data/lib/moneta/file.rb +0 -91
  203. data/lib/moneta/lmc.rb +0 -52
  204. data/lib/moneta/memcache.rb +0 -52
  205. data/lib/moneta/memory.rb +0 -11
  206. data/lib/moneta/mongodb.rb +0 -58
  207. data/lib/moneta/redis.rb +0 -49
  208. data/lib/moneta/rufus.rb +0 -41
  209. data/lib/moneta/s3.rb +0 -162
  210. data/lib/moneta/sdbm.rb +0 -33
  211. data/lib/moneta/tyrant.rb +0 -58
  212. data/lib/moneta/xattr.rb +0 -58
@@ -1,52 +0,0 @@
1
- begin
2
- require "memcached"
3
- rescue LoadError
4
- require "memcache"
5
- rescue LoadError
6
- puts "You need the memcache gem to use the Memcache moneta store"
7
- exit
8
- end
9
-
10
- module Moneta
11
- class Memcache
12
- include Defaults
13
-
14
- def initialize(options = {})
15
- @cache = MemCache.new(options.delete(:server), options)
16
- end
17
-
18
- def key?(key)
19
- !self[key].nil?
20
- end
21
-
22
- alias has_key? key?
23
-
24
- def [](key)
25
- @cache.get(key)
26
- end
27
-
28
- def []=(key, value)
29
- store(key, value)
30
- end
31
-
32
- def delete(key)
33
- value = self[key]
34
- @cache.delete(key) if value
35
- value
36
- end
37
-
38
- def store(key, value, options = {})
39
- args = [key, value, options[:expires_in]].compact
40
- @cache.set(*args)
41
- end
42
-
43
- def update_key(key, options = {})
44
- val = self[key]
45
- self.store(key, val, options)
46
- end
47
-
48
- def clear
49
- @cache.flush_all
50
- end
51
- end
52
- end
@@ -1,11 +0,0 @@
1
- module Moneta
2
- class Memory < Hash
3
- include Expires
4
-
5
- def initialize(*args)
6
- @expiration = {}
7
- super
8
- end
9
-
10
- end
11
- end
@@ -1,58 +0,0 @@
1
- begin
2
- require "mongo"
3
- rescue LoadError
4
- puts "You need the mongo gem to use the MongoDB moneta store"
5
- exit
6
- end
7
-
8
- module Moneta
9
- class MongoDB
10
- include Defaults
11
-
12
- def initialize(options = {})
13
- options = {
14
- :host => ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
15
- :port => ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT,
16
- :db => 'cache',
17
- :collection => 'cache'
18
- }.update(options)
19
- conn = XGen::Mongo::Driver::Mongo.new(options[:host], options[:port])
20
- @cache = conn.db(options[:db]).collection(options[:collection])
21
- end
22
-
23
- def key?(key)
24
- !!self[key]
25
- end
26
-
27
- def [](key)
28
- res = @cache.find_first('_id' => key)
29
- res = nil if res && res['expires'] && Time.now > res['expires']
30
- res && res['data']
31
- end
32
-
33
- def []=(key, value)
34
- store(key, value)
35
- end
36
-
37
- def delete(key)
38
- value = self[key]
39
- @cache.remove('_id' => key) if value
40
- value
41
- end
42
-
43
- def store(key, value, options = {})
44
- exp = options[:expires_in] ? (Time.now + options[:expires_in]) : nil
45
- @cache.repsert({ '_id' => key }, { '_id' => key, 'data' => value, 'expires' => exp })
46
- end
47
-
48
- def update_key(key, options = {})
49
- val = self[key]
50
- self.store(key, val, options)
51
- end
52
-
53
- def clear
54
- @cache.clear
55
- end
56
- end
57
- end
58
-
@@ -1,49 +0,0 @@
1
- begin
2
- require "redis"
3
- rescue LoadError
4
- puts "You need the redis gem to use the Redis store"
5
- exit
6
- end
7
-
8
- module Moneta
9
- class Redis
10
- include Defaults
11
-
12
- def initialize(options = {})
13
- @cache = ::Redis.new(options)
14
- end
15
-
16
- def key?(key)
17
- !@cache[key].nil?
18
- end
19
-
20
- alias has_key? key?
21
-
22
- def [](key)
23
- @cache.get(key)
24
- end
25
-
26
- def []=(key, value)
27
- store(key, value)
28
- end
29
-
30
- def delete(key)
31
- value = @cache[key]
32
- @cache.delete(key) if value
33
- value
34
- end
35
-
36
- def store(key, value, options = {})
37
- @cache.set(key, value, options[:expires_in])
38
- end
39
-
40
- def update_key(key, options = {})
41
- val = @cache[key]
42
- self.store(key, val, options)
43
- end
44
-
45
- def clear
46
- @cache.flush_db
47
- end
48
- end
49
- end
@@ -1,41 +0,0 @@
1
- begin
2
- require "rufus/tokyo"
3
- rescue LoadError
4
- puts "You need the rufus gem to use the Rufus moneta store"
5
- exit
6
- end
7
-
8
- module Moneta
9
- class BasicRufus < ::Rufus::Tokyo::Cabinet
10
- include Defaults
11
-
12
- def initialize(options = {})
13
- file = options[:file]
14
- super("#{file}.tch")
15
- end
16
-
17
- def key?(key)
18
- !!self[key]
19
- end
20
-
21
- def [](key)
22
- if val = super
23
- Marshal.load(val.unpack("m")[0])
24
- end
25
- end
26
-
27
- def []=(key, value)
28
- super(key, [Marshal.dump(value)].pack("m"))
29
- end
30
- end
31
-
32
- class Rufus < BasicRufus
33
- include Expires
34
-
35
- def initialize(options = {})
36
- file = options[:file]
37
- @expiration = BasicRufus.new(:file => "#{file}_expires")
38
- super
39
- end
40
- end
41
- end
@@ -1,162 +0,0 @@
1
- begin
2
- require "right_aws"
3
- rescue LoadError
4
- puts "You need the RightScale AWS gem to use the S3 moneta store"
5
- exit
6
- end
7
-
8
- module Moneta
9
- # An S3 implementation of Moneta
10
- #
11
- # Example usage:
12
- #
13
- # require 'rubygems'
14
- # require 'moneta'
15
- # require 'moneta/s3'
16
- #
17
- # store = Moneta::S3.new(
18
- # :access_key_id => 'ACCESS_KEY_ID',
19
- # :secret_access_key => 'SECRET_ACCESS_KEY',
20
- # :bucket => 'a_bucket'
21
- # )
22
- # store['somefile']
23
- class S3
24
- # Initialize the Moneta::S3 store.
25
- #
26
- # Required values passed in the options hash:
27
- # * <tt>:access_key_id</tt>: The access id key
28
- # * <tt>:secret_access_key</tt>: The secret key
29
- # * <tt>:bucket</tt>: The name of bucket. Will be created if it doesn't
30
- # exist.
31
- # * <tt>:multi_thread</tt>: Set to true if using threading
32
- def initialize(options = {})
33
- validate_options(options)
34
- s3 = RightAws::S3.new(
35
- options[:access_key_id],
36
- options[:secret_access_key],
37
- {
38
- :logger => logger,
39
- :multi_thread => options.delete(:multi_thread) || false
40
- }
41
- )
42
- @bucket = s3.bucket(options.delete(:bucket), true)
43
- end
44
-
45
- def key?(key)
46
- !s3_key(key).nil?
47
- end
48
-
49
- alias has_key? key?
50
-
51
- def [](key)
52
- get(key)
53
- end
54
-
55
- def []=(key, value)
56
- store(key, value)
57
- end
58
-
59
- def delete(key)
60
- k = s3_key(key)
61
- if k
62
- value = k.get
63
- k.delete
64
- value
65
- end
66
- end
67
-
68
- # Store the key/value pair.
69
- #
70
- # Options:
71
- # *<tt>:meta_headers</tt>: Meta headers passed to S3
72
- # *<tt>:perms</tt>: Permissions passed to S3
73
- # *<tt>:headers</tt>: Headers sent as part of the PUT request
74
- # *<tt>:expires_in</tt>: Number of seconds until expiration
75
- def store(key, value, options = {})
76
- debug "store(key=#{key}, value=#{value}, options=#{options.inspect})"
77
- meta_headers = meta_headers_from_options(options)
78
- perms = options[:perms]
79
- headers = options[:headers] || {}
80
-
81
- case value
82
- when IO
83
- @bucket.put(key, value.read, meta_headers, perms, headers)
84
- else
85
- @bucket.put(key, value, meta_headers, perms, headers)
86
- end
87
- end
88
-
89
- def update_key(key, options = {})
90
- debug "update_key(key=#{key}, options=#{options.inspect})"
91
- k = s3_key(key, false)
92
- k.save_meta(meta_headers_from_options(options)) unless k.nil?
93
- end
94
-
95
- def clear
96
- @bucket.clear
97
- end
98
-
99
- protected
100
- def logger
101
- @logger ||= begin
102
- logger = Logger.new(STDOUT)
103
- logger.level = Logger::FATAL
104
- logger
105
- end
106
- end
107
-
108
- private
109
- def validate_options(options)
110
- unless options[:access_key_id]
111
- raise RuntimeError, ":access_key_id is required in options"
112
- end
113
- unless options[:secret_access_key]
114
- raise RuntimeError, ":secret_access_key is required in options"
115
- end
116
- unless options[:bucket]
117
- raise RuntimeError, ":bucket is required in options"
118
- end
119
- end
120
-
121
- def get(key)
122
- k = s3_key(key)
123
- k.nil? ? nil : k.get
124
- end
125
-
126
- def s3_key(key, nil_if_expired=true)
127
- begin
128
- s3_key = @bucket.key(key, true)
129
- if s3_key.exists?
130
- logger.debug "[Moneta::S3] key exists: #{key}"
131
- if s3_key.meta_headers.has_key?('expires-at')
132
- expires_at = Time.parse(s3_key.meta_headers['expires-at'])
133
- if Time.now > expires_at && nil_if_expired
134
- # TODO delete the object?
135
- debug "key expired: #{key} (@#{s3_key.meta_headers['expires-at']})"
136
- return nil
137
- end
138
- end
139
- return s3_key
140
- else
141
- debug "key does not exist: #{key}"
142
- end
143
- rescue RightAws::AwsError => e
144
- debug "key does not exist: #{key}"
145
- end
146
- nil
147
- end
148
-
149
- def meta_headers_from_options(options={})
150
- meta_headers = options[:meta_headers] || {}
151
- if options[:expires_in]
152
- meta_headers['expires-at'] = (Time.now + options[:expires_in]).rfc2822
153
- end
154
- debug "setting expires-at: #{meta_headers['expires-at']}"
155
- meta_headers
156
- end
157
-
158
- def debug(message)
159
- logger.debug "[Moneta::S3] #{message}"
160
- end
161
- end
162
- end
@@ -1,33 +0,0 @@
1
- require "sdbm"
2
-
3
- module Moneta
4
- class BasicSDBM < ::SDBM
5
- include Defaults
6
-
7
- def [](key)
8
- if val = super
9
- Marshal.load(val)
10
- end
11
- end
12
-
13
- def []=(key, value)
14
- super(key, Marshal.dump(value))
15
- end
16
-
17
- def delete(key)
18
- if val = super
19
- Marshal.load(val)
20
- end
21
- end
22
- end
23
-
24
- class SDBM < BasicSDBM
25
- include Expires
26
-
27
- def initialize(options = {})
28
- raise "No :file option specified" unless file = options[:file]
29
- @expiration = BasicSDBM.new("#{file}_expires")
30
- super(file)
31
- end
32
- end
33
- end
@@ -1,58 +0,0 @@
1
- begin
2
- require "rufus/tokyo/tyrant"
3
- rescue LoadError
4
- puts "You need the rufus gem to use the Tyrant moneta store"
5
- exit
6
- end
7
-
8
- module Moneta
9
- class Tyrant < ::Rufus::Tokyo::Tyrant
10
- include Defaults
11
-
12
- module Implementation
13
- def initialize(options = {})
14
- host = options[:host]
15
- port = options[:port]
16
- super(host, port)
17
- end
18
-
19
- def key?(key)
20
- !!self[key]
21
- end
22
-
23
- def [](key)
24
- if val = super
25
- Marshal.load(val.unpack("m")[0])
26
- end
27
- end
28
-
29
- def []=(key, value)
30
- super(key, [Marshal.dump(value)].pack("m"))
31
- end
32
- end
33
-
34
- include Implementation
35
- include Expires
36
-
37
- def initialize(options = {})
38
- super
39
- @expiration = Expiration.new(options)
40
- end
41
-
42
- class Expiration < ::Rufus::Tokyo::Tyrant
43
- include Implementation
44
-
45
- def [](key)
46
- super("#{key}__expiration")
47
- end
48
-
49
- def []=(key, value)
50
- super("#{key}__expiration", value)
51
- end
52
-
53
- def delete(key)
54
- super("#{key}__expiration")
55
- end
56
- end
57
- end
58
- end