moneta 0.7.19 → 0.7.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -1
  3. data/CHANGES +11 -0
  4. data/Gemfile +9 -0
  5. data/README.md +15 -2
  6. data/lib/moneta.rb +8 -9
  7. data/lib/moneta/adapters/cassandra.rb +11 -11
  8. data/lib/moneta/adapters/lmdb.rb +93 -0
  9. data/lib/moneta/adapters/lruhash.rb +16 -10
  10. data/lib/moneta/adapters/mongo.rb +2 -3
  11. data/lib/moneta/adapters/sequel.rb +12 -5
  12. data/lib/moneta/cache.rb +1 -2
  13. data/lib/moneta/proxy.rb +1 -0
  14. data/lib/moneta/synchronize.rb +2 -3
  15. data/lib/moneta/transformer/config.rb +5 -3
  16. data/lib/moneta/utils.rb +8 -0
  17. data/lib/moneta/version.rb +1 -1
  18. data/script/benchmarks +1 -0
  19. data/script/generate-specs +139 -92
  20. data/script/travis-logs +2 -1
  21. data/spec/helper.rb +2 -2
  22. data/spec/moneta/adapter_activerecord_exisiting_connection_spec.rb +5 -0
  23. data/spec/moneta/adapter_activerecord_spec.rb +5 -0
  24. data/spec/moneta/adapter_cassandra_spec.rb +5 -0
  25. data/spec/moneta/adapter_cassandra_with_default_expires_spec.rb +5 -0
  26. data/spec/moneta/adapter_client_spec.rb +5 -0
  27. data/spec/moneta/adapter_cookie_spec.rb +4 -0
  28. data/spec/moneta/adapter_couch_spec.rb +12 -11
  29. data/spec/moneta/adapter_datamapper_spec.rb +5 -0
  30. data/spec/moneta/adapter_daybreak_spec.rb +5 -0
  31. data/spec/moneta/adapter_dbm_spec.rb +5 -0
  32. data/spec/moneta/adapter_file_spec.rb +5 -0
  33. data/spec/moneta/adapter_fog_spec.rb +5 -0
  34. data/spec/moneta/adapter_gdbm_spec.rb +5 -0
  35. data/spec/moneta/adapter_hbase_spec.rb +5 -0
  36. data/spec/moneta/adapter_kyotocabinet_spec.rb +5 -0
  37. data/spec/moneta/adapter_leveldb_spec.rb +5 -0
  38. data/spec/moneta/adapter_lmdb_spec.rb +32 -0
  39. data/spec/moneta/adapter_lmdb_with_db_spec.rb +32 -0
  40. data/spec/moneta/adapter_localmemcache_spec.rb +5 -0
  41. data/spec/moneta/adapter_lruhash_spec.rb +4 -0
  42. data/spec/moneta/adapter_memcached_dalli_spec.rb +5 -0
  43. data/spec/moneta/adapter_memcached_dalli_with_default_expires_spec.rb +5 -0
  44. data/spec/moneta/adapter_memcached_native_spec.rb +5 -0
  45. data/spec/moneta/adapter_memcached_native_with_default_expires_spec.rb +5 -0
  46. data/spec/moneta/adapter_memcached_spec.rb +5 -0
  47. data/spec/moneta/adapter_memcached_with_default_expires_spec.rb +5 -0
  48. data/spec/moneta/adapter_memory_spec.rb +42 -0
  49. data/spec/moneta/adapter_mongo_spec.rb +12 -0
  50. data/spec/moneta/adapter_mongo_with_default_expires_spec.rb +12 -0
  51. data/spec/moneta/adapter_pstore_spec.rb +57 -0
  52. data/spec/moneta/adapter_redis_spec.rb +5 -0
  53. data/spec/moneta/adapter_redis_with_default_expires_spec.rb +5 -0
  54. data/spec/moneta/adapter_restclient_spec.rb +5 -0
  55. data/spec/moneta/adapter_riak_spec.rb +5 -0
  56. data/spec/moneta/adapter_sdbm_spec.rb +5 -0
  57. data/spec/moneta/adapter_sequel_spec.rb +5 -0
  58. data/spec/moneta/adapter_sqlite_spec.rb +5 -0
  59. data/spec/moneta/adapter_tdb_spec.rb +5 -0
  60. data/spec/moneta/adapter_tokyocabinet_bdb_spec.rb +5 -0
  61. data/spec/moneta/adapter_tokyocabinet_hdb_spec.rb +5 -0
  62. data/spec/moneta/adapter_tokyotyrant_spec.rb +5 -0
  63. data/spec/moneta/adapter_yaml_spec.rb +1 -0
  64. data/spec/moneta/cache_file_memory_spec.rb +5 -0
  65. data/spec/moneta/cache_memory_null_spec.rb +4 -0
  66. data/spec/moneta/expires_file_spec.rb +5 -0
  67. data/spec/moneta/expires_memory_spec.rb +42 -0
  68. data/spec/moneta/expires_memory_with_default_expires_spec.rb +42 -0
  69. data/spec/moneta/lock_spec.rb +42 -0
  70. data/spec/moneta/mutex_spec.rb +1 -0
  71. data/spec/moneta/null_adapter_spec.rb +16 -0
  72. data/spec/moneta/optionmerger_spec.rb +1 -0
  73. data/spec/moneta/pool_spec.rb +5 -0
  74. data/spec/moneta/proxy_expires_memory_spec.rb +42 -0
  75. data/spec/moneta/proxy_redis_spec.rb +5 -0
  76. data/spec/moneta/semaphore_spec.rb +1 -0
  77. data/spec/moneta/shared_tcp_spec.rb +5 -0
  78. data/spec/moneta/shared_unix_spec.rb +5 -0
  79. data/spec/moneta/stack_file_memory_spec.rb +5 -0
  80. data/spec/moneta/stack_memory_file_spec.rb +5 -0
  81. data/spec/moneta/{simple_activerecord_spec.rb → standard_activerecord_spec.rb} +59 -2
  82. data/spec/moneta/{simple_activerecord_with_expires_spec.rb → standard_activerecord_with_expires_spec.rb} +59 -2
  83. data/spec/moneta/{simple_cassandra_spec.rb → standard_cassandra_spec.rb} +59 -2
  84. data/spec/moneta/{simple_client_tcp_spec.rb → standard_client_tcp_spec.rb} +59 -2
  85. data/spec/moneta/standard_client_unix_spec.rb +254 -0
  86. data/spec/moneta/{simple_couch_spec.rb → standard_couch_spec.rb} +59 -2
  87. data/spec/moneta/{simple_couch_with_expires_spec.rb → standard_couch_with_expires_spec.rb} +59 -2
  88. data/spec/moneta/{simple_datamapper_spec.rb → standard_datamapper_spec.rb} +59 -2
  89. data/spec/moneta/{simple_datamapper_with_expires_spec.rb → standard_datamapper_with_expires_spec.rb} +59 -2
  90. data/spec/moneta/{simple_datamapper_with_repository_spec.rb → standard_datamapper_with_repository_spec.rb} +59 -2
  91. data/spec/moneta/{simple_daybreak_spec.rb → standard_daybreak_spec.rb} +59 -2
  92. data/spec/moneta/{simple_daybreak_with_expires_spec.rb → standard_daybreak_with_expires_spec.rb} +59 -2
  93. data/spec/moneta/{simple_dbm_spec.rb → standard_dbm_spec.rb} +59 -2
  94. data/spec/moneta/{simple_dbm_with_expires_spec.rb → standard_dbm_with_expires_spec.rb} +59 -2
  95. data/spec/moneta/{simple_file_spec.rb → standard_file_spec.rb} +59 -2
  96. data/spec/moneta/{simple_file_with_expires_spec.rb → standard_file_with_expires_spec.rb} +59 -2
  97. data/spec/moneta/{simple_fog_spec.rb → standard_fog_spec.rb} +59 -2
  98. data/spec/moneta/{simple_fog_with_expires_spec.rb → standard_fog_with_expires_spec.rb} +60 -3
  99. data/spec/moneta/{simple_gdbm_spec.rb → standard_gdbm_spec.rb} +59 -2
  100. data/spec/moneta/{simple_gdbm_with_expires_spec.rb → standard_gdbm_with_expires_spec.rb} +59 -2
  101. data/spec/moneta/{simple_hashfile_spec.rb → standard_hashfile_spec.rb} +59 -2
  102. data/spec/moneta/{simple_hashfile_with_expires_spec.rb → standard_hashfile_with_expires_spec.rb} +59 -2
  103. data/spec/moneta/{simple_hbase_spec.rb → standard_hbase_spec.rb} +59 -2
  104. data/spec/moneta/{simple_hbase_with_expires_spec.rb → standard_hbase_with_expires_spec.rb} +59 -2
  105. data/spec/moneta/{simple_kyotocabinet_spec.rb → standard_kyotocabinet_spec.rb} +59 -2
  106. data/spec/moneta/{simple_kyotocabinet_with_expires_spec.rb → standard_kyotocabinet_with_expires_spec.rb} +59 -2
  107. data/spec/moneta/{simple_leveldb_spec.rb → standard_leveldb_spec.rb} +59 -2
  108. data/spec/moneta/{simple_leveldb_with_expires_spec.rb → standard_leveldb_with_expires_spec.rb} +59 -2
  109. data/spec/moneta/{simple_client_unix_spec.rb → standard_lmdb_spec.rb} +59 -5
  110. data/spec/moneta/standard_lmdb_with_expires_spec.rb +253 -0
  111. data/spec/moneta/{simple_localmemcache_spec.rb → standard_localmemcache_spec.rb} +59 -2
  112. data/spec/moneta/{simple_localmemcache_with_expires_spec.rb → standard_localmemcache_with_expires_spec.rb} +59 -2
  113. data/spec/moneta/{simple_lruhash_spec.rb → standard_lruhash_spec.rb} +44 -2
  114. data/spec/moneta/{simple_lruhash_with_expires_spec.rb → standard_lruhash_with_expires_spec.rb} +44 -2
  115. data/spec/moneta/{simple_memcached_dalli_spec.rb → standard_memcached_dalli_spec.rb} +59 -2
  116. data/spec/moneta/{simple_memcached_native_spec.rb → standard_memcached_native_spec.rb} +59 -2
  117. data/spec/moneta/{simple_memcached_spec.rb → standard_memcached_spec.rb} +59 -2
  118. data/spec/moneta/{simple_memory_spec.rb → standard_memory_spec.rb} +44 -2
  119. data/spec/moneta/{simple_memory_with_compress_spec.rb → standard_memory_with_compress_spec.rb} +44 -2
  120. data/spec/moneta/{simple_memory_with_expires_spec.rb → standard_memory_with_expires_spec.rb} +44 -2
  121. data/spec/moneta/{simple_memory_with_json_key_serializer_spec.rb → standard_memory_with_json_key_serializer_spec.rb} +12 -2
  122. data/spec/moneta/{simple_memory_with_json_serializer_spec.rb → standard_memory_with_json_serializer_spec.rb} +4 -3
  123. data/spec/moneta/{simple_memory_with_json_value_serializer_spec.rb → standard_memory_with_json_value_serializer_spec.rb} +12 -3
  124. data/spec/moneta/{simple_memory_with_prefix_spec.rb → standard_memory_with_prefix_spec.rb} +44 -2
  125. data/spec/moneta/{simple_memory_with_snappy_compress_spec.rb → standard_memory_with_snappy_compress_spec.rb} +44 -2
  126. data/spec/moneta/{simple_mongo_spec.rb → standard_mongo_spec.rb} +59 -2
  127. data/spec/moneta/{simple_null_spec.rb → standard_null_spec.rb} +29 -2
  128. data/spec/moneta/{simple_pstore_spec.rb → standard_pstore_spec.rb} +59 -2
  129. data/spec/moneta/{simple_pstore_with_expires_spec.rb → standard_pstore_with_expires_spec.rb} +59 -2
  130. data/spec/moneta/{simple_redis_spec.rb → standard_redis_spec.rb} +59 -2
  131. data/spec/moneta/{simple_restclient_spec.rb → standard_restclient_spec.rb} +59 -2
  132. data/spec/moneta/{simple_riak_spec.rb → standard_riak_spec.rb} +59 -2
  133. data/spec/moneta/{simple_riak_with_expires_spec.rb → standard_riak_with_expires_spec.rb} +59 -2
  134. data/spec/moneta/{simple_sdbm_spec.rb → standard_sdbm_spec.rb} +59 -2
  135. data/spec/moneta/{simple_sdbm_with_expires_spec.rb → standard_sdbm_with_expires_spec.rb} +59 -2
  136. data/spec/moneta/{simple_sequel_spec.rb → standard_sequel_spec.rb} +60 -3
  137. data/spec/moneta/{simple_sequel_with_expires_spec.rb → standard_sequel_with_expires_spec.rb} +60 -3
  138. data/spec/moneta/{simple_sqlite_spec.rb → standard_sqlite_spec.rb} +59 -2
  139. data/spec/moneta/{simple_sqlite_with_expires_spec.rb → standard_sqlite_with_expires_spec.rb} +59 -2
  140. data/spec/moneta/{simple_tdb_spec.rb → standard_tdb_spec.rb} +59 -2
  141. data/spec/moneta/{simple_tdb_with_expires_spec.rb → standard_tdb_with_expires_spec.rb} +59 -2
  142. data/spec/moneta/{simple_tokyocabinet_spec.rb → standard_tokyocabinet_spec.rb} +59 -2
  143. data/spec/moneta/{simple_tokyocabinet_with_expires_spec.rb → standard_tokyocabinet_with_expires_spec.rb} +59 -2
  144. data/spec/moneta/{simple_tokyotyrant_spec.rb → standard_tokyotyrant_spec.rb} +59 -2
  145. data/spec/moneta/{simple_tokyotyrant_with_expires_spec.rb → standard_tokyotyrant_with_expires_spec.rb} +59 -2
  146. data/spec/moneta/{simple_yaml_spec.rb → standard_yaml_spec.rb} +59 -2
  147. data/spec/moneta/{simple_yaml_with_expires_spec.rb → standard_yaml_with_expires_spec.rb} +59 -2
  148. data/spec/moneta/transformer_bencode_spec.rb +1 -0
  149. data/spec/moneta/transformer_bert_spec.rb +1 -0
  150. data/spec/moneta/transformer_bson_spec.rb +1 -0
  151. data/spec/moneta/transformer_bzip2_spec.rb +4 -0
  152. data/spec/moneta/transformer_json_spec.rb +2 -1
  153. data/spec/moneta/transformer_key_inspect_spec.rb +10 -0
  154. data/spec/moneta/transformer_key_marshal_spec.rb +42 -0
  155. data/spec/moneta/transformer_key_to_s_spec.rb +10 -0
  156. data/spec/moneta/transformer_key_yaml_spec.rb +42 -0
  157. data/spec/moneta/transformer_lz4_spec.rb +4 -0
  158. data/spec/moneta/transformer_lzma_spec.rb +4 -0
  159. data/spec/moneta/transformer_lzo_spec.rb +4 -0
  160. data/spec/moneta/transformer_marshal_base64_spec.rb +42 -0
  161. data/spec/moneta/transformer_marshal_city128_spec.rb +42 -0
  162. data/spec/moneta/transformer_marshal_city32_spec.rb +42 -0
  163. data/spec/moneta/transformer_marshal_city64_spec.rb +42 -0
  164. data/spec/moneta/transformer_marshal_escape_spec.rb +42 -0
  165. data/spec/moneta/transformer_marshal_hex_spec.rb +194 -0
  166. data/spec/moneta/transformer_marshal_hmac_spec.rb +42 -0
  167. data/spec/moneta/transformer_marshal_md5_spec.rb +42 -0
  168. data/spec/moneta/transformer_marshal_md5_spread_spec.rb +42 -0
  169. data/spec/moneta/transformer_marshal_prefix_spec.rb +42 -0
  170. data/spec/moneta/transformer_marshal_qp_spec.rb +42 -0
  171. data/spec/moneta/transformer_marshal_rmd160_spec.rb +42 -0
  172. data/spec/moneta/transformer_marshal_sha1_spec.rb +42 -0
  173. data/spec/moneta/transformer_marshal_sha256_spec.rb +42 -0
  174. data/spec/moneta/transformer_marshal_sha384_spec.rb +42 -0
  175. data/spec/moneta/transformer_marshal_sha512_spec.rb +42 -0
  176. data/spec/moneta/transformer_marshal_spec.rb +42 -0
  177. data/spec/moneta/transformer_marshal_truncate_spec.rb +42 -0
  178. data/spec/moneta/transformer_marshal_uuencode_spec.rb +42 -0
  179. data/spec/moneta/transformer_msgpack_spec.rb +1 -0
  180. data/spec/moneta/transformer_ox_spec.rb +42 -0
  181. data/spec/moneta/transformer_php_spec.rb +55 -0
  182. data/spec/moneta/transformer_quicklz_spec.rb +4 -0
  183. data/spec/moneta/transformer_snappy_spec.rb +4 -0
  184. data/spec/moneta/transformer_tnet_spec.rb +1 -0
  185. data/spec/moneta/transformer_value_marshal_spec.rb +42 -0
  186. data/spec/moneta/transformer_value_yaml_spec.rb +42 -0
  187. data/spec/moneta/transformer_yaml_spec.rb +42 -0
  188. data/spec/moneta/transformer_zlib_spec.rb +4 -0
  189. data/spec/moneta/weak_create_spec.rb +5 -0
  190. data/spec/moneta/weak_increment_spec.rb +5 -0
  191. data/spec/monetaspecs.rb +26531 -16522
  192. metadata +145 -133
  193. data/script/kill-travis +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54ab5446cbb72cf10100e2e72680c4624113aaa0
4
- data.tar.gz: c3337a129506fdeab6624542b37ada15a9c16c20
3
+ metadata.gz: d992dc7597746374044079fd618a13b1e988766a
4
+ data.tar.gz: fec8939551039410e2412294f2fa19755413edfe
5
5
  SHA512:
6
- metadata.gz: dc94d4af7c904ad023cee82ee3ec408e9685273362a94a6cf620ba0d108ea69b660ea8a737bd91491faacd10c09d0e5b1942f429b19fb010df806980e9f1f88b
7
- data.tar.gz: 50a2df5e71906df99c2954ed1efb8ca2986234db51f21565c53bbbbdf93e2b07f123d041c6c165a0b24e9876852cbc23d2b4877e94261cf0f8b4bda946da53c1
6
+ metadata.gz: 13fa047663d93ec878871a9aaac054589dbc3135994bb320575b2c55185d88a3b395658350b2d140052ca9217a2b5558d17513f1354a409759fb9e8b399778ab
7
+ data.tar.gz: a93d886f2b8ca3ddb1ab258603ba3b3b9ceb318d814b99022c107e9aa138041ccd564f679e90ea0e18b440ef4421a46f405b578f854388f5fcf0503881b7cdb6
@@ -8,7 +8,6 @@ rvm:
8
8
  - rbx-19mode
9
9
  - rbx-18mode
10
10
  before_install:
11
- - script/kill-travis
12
11
  #- script/install-kyotocabinet
13
12
  - sudo apt-get install -qq libtokyocabinet8 libtokyocabinet-dev liblzo2-dev libtdb-dev libleveldb-dev tokyotyrant
14
13
  - script/start-services
data/CHANGES CHANGED
@@ -1,3 +1,14 @@
1
+ 0.7.20
2
+
3
+ * Adapters::LRUHash: add option :max_value
4
+ * Moneta.new(:Couch, :Riak, :RestClient): use urlencode instead of base64 for key encoding)
5
+ * Transformer: Add :hex encoder
6
+ * Transformer: Don't wrap object in array for JSON serialization
7
+ * Transformer: Add :php serializer
8
+ * Moneta.new(:Sequel) - Don't encode blob data using base64
9
+ * Moneta::Adapters::LMDB added (Symas Lightning Memory-Mapped Database)
10
+ * Moneta::Adapters::Sequel - Fix for https://github.com/jeremyevans/sequel/issues/715
11
+
1
12
  0.7.19
2
13
 
3
14
  * ActionDispatch::Session::MonetaStore fixed for Rails 4
data/Gemfile CHANGED
@@ -22,6 +22,7 @@ gem 'ox', :platforms => :ruby
22
22
  gem 'msgpack', :platforms => :ruby
23
23
  gem 'msgpack-jruby', :platforms => :jruby
24
24
  gem 'bert', :platforms => :ruby
25
+ gem 'php_serialize'
25
26
 
26
27
  # Compressors used by Transformer
27
28
  if RUBY_VERSION < '2.0'
@@ -57,6 +58,9 @@ gem 'tokyotyrant'
57
58
  #gem 'localmemcache'
58
59
  gem 'tdb', :platforms => :ruby
59
60
  gem 'leveldb-ruby', :platforms => :ruby
61
+ if RUBY_VERSION >= '1.9'
62
+ gem 'lmdb', :platforms => :mri
63
+ end
60
64
  if RUBY_VERSION < '2.0'
61
65
  gem 'tokyocabinet', :platforms => :ruby
62
66
  end
@@ -82,3 +86,8 @@ gem 'rack-cache'
82
86
  # Rails integration testing
83
87
  gem 'actionpack', *rails_version
84
88
  gem 'minitest', '~> 4.7.4'
89
+
90
+ # Fix versions for old ruby 1.8
91
+ if RUBY_VERSION < '1.9'
92
+ gem 'nokogiri', '< 1.6'
93
+ end
data/README.md CHANGED
@@ -105,6 +105,7 @@ Out of the box, it supports the following backends. Use the backend name symbol
105
105
  * [GDBM](http://www.ruby-doc.org/stdlib/libdoc/gdbm/rdoc/GDBM.html) (`:GDBM`)
106
106
  * [HBase](http://hbase.apache.org/) (`:HBase`)
107
107
  * [LevelDB](http://code.google.com/p/leveldb/) (`:LevelDB`)
108
+ * [LMDB](http://symas.com/mdb/) (`:LMDB`)
108
109
  * [Redis](http://redis.io/) (`:Redis`)
109
110
  * [Riak](http://docs.basho.com/) (`:Riak`)
110
111
  * [SDBM](http://www.ruby-doc.org/stdlib/libdoc/sdbm/rdoc/SDBM.html) (`:SDBM`)
@@ -145,6 +146,8 @@ __NOTE:__ <a name="backend-matrix">The backend matrix</a> is much more readable
145
146
 
146
147
  <tr><td>File</td><td>-</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#F44">✗</td><td style="text-align:center;background:#5F5">✓</td><td>File store</td></tr>
147
148
 
149
+ <tr><td>LMDB</td><td>lmdb</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#F44">✗</td><td style="text-align:center;background:#5F5">✓</td><td><a href="http://symas.com/mdb/">Symas Lightning Memory-Mapped Database (LMDB)</a></td></tr>
150
+
148
151
  <tr><td>Sequel</td><td>sequel</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#F44">✗</td><td style="text-align:center;background:#5F5">✓</td><td><a href="http://sequel.rubyforge.org/">Sequel</a> ORM</td></tr>
149
152
 
150
153
  <tr><td>TokyoTyrant</td><td>tokyotyrant or ruby-tokyotyrant</td><td style="text-align:center;background:#F44">✗</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#F44">✗</td><td style="text-align:center;background:#5F5">✓</td><td><a href="http://fallabs.com/tokyotyrant/">TokyoTyrant</a> database</td></tr>
@@ -210,7 +213,7 @@ __NOTE:__ <a name="backend-matrix">The backend matrix</a> is much more readable
210
213
  * [1]: Make adapters thread-safe by using `Moneta::Lock` or by passing the option `:threadsafe => true` to `Moneta#new`. There is also `Moneta::Pool` which can be used to share a store between multiple threads if the store is multi-process safe. I recommend to add the option `:threadsafe` to ensure thread-safety since for example under JRuby and Rubinius even the basic datastructures are not thread safe due to the lack of a global interpreter lock (GIL). This differs from MRI where some adapters might appear thread safe already but only due to the GIL.
211
214
  * [2]: Share a Moneta store between multiple processes using `Moneta::Shared` (See below).
212
215
  * [3]: Add expiration support by using `Moneta::Expires` or by passing the option `:expires => true` to `Moneta#new`.
213
- * [4]: There are some servers which use the memcached protocol but which are persistent (e.g. [MemcacheDB](http://memcachedb.org/), [Kai](http://sourceforge.net/apps/mediawiki/kai), [IronCache](http://dev.iron.io/cache/reference/memcache/), [Roma](https://github.com/roma/roma/tree) and [Flare](http://labs.gree.jp/Top/OpenSource/Flare-en.html))
216
+ * [4]: There are some servers which use the memcached protocol but which are persistent (e.g. [MemcacheDB](http://memcachedb.org/), [Kai](http://sourceforge.net/apps/mediawiki/kai), [IronCache](http://dev.iron.io/cache/reference/memcache/), [Roma](https://github.com/roma/roma/tree), [Flare](http://labs.gree.jp/Top/OpenSource/Flare-en.html) and [Kumofs](https://github.com/etolabo/kumofs))
214
217
  * [5]: Depends on server
215
218
  * [6]: Store is multi-process safe because it is an in-memory store, values are not shared between multiple processes
216
219
  * [7]: Store is multi-process safe, but not synchronized automatically between multiple processes
@@ -229,7 +232,7 @@ add additional features to storage backends:
229
232
  * `Moneta::Expires` to add expiration support to stores which don't support it natively. Add it in the builder using `use :Expires`.
230
233
  * `Moneta::Stack` to stack multiple stores (Read returns result from first where the key is found, writes go to all stores). Add it in the builder using `use(:Stack) {}`.
231
234
  * `Moneta::Transformer` transforms keys and values (Marshal, YAML, JSON, Base64, MD5, ...). Add it in the builder using `use :Transformer`.
232
- * `Moneta::Cache` combine two stores, one as backend and one as cache (e.g. `Moneta::Adapters::File` + `Moneta::Adapters::Memory`). Add it in the builder using `use(:Cache) {}`.
235
+ * `Moneta::Cache` combine two stores, one as backend and one as cache (e.g. `Moneta::Adapters::File` + `Moneta::Adapters::LRUHash`). Add it in the builder using `use(:Cache) {}`.
233
236
  * `Moneta::Lock` to make store thread safe. Add it in the builder using `use :Lock`.
234
237
  * `Moneta::Pool` to create a pool of stores as a means of making the store thread safe. Add it in the builder using `use(:Pool) {}`.
235
238
  * `Moneta::Logger` to log database accesses. Add it in the builder using `use :Logger`.
@@ -247,11 +250,13 @@ Supported serializers:
247
250
  * Marshal (`:marshal`)
248
251
  * MessagePack (`:msgpack`)
249
252
  * Ox (`:ox`)
253
+ * PHP (`:php`)
250
254
  * TNetStrings (`:tnet`)
251
255
  * YAML (`:yaml`)
252
256
 
253
257
  Supported value compressors:
254
258
 
259
+ * Bzip2 (`:bzip2`)
255
260
  * LZ4 (`:lz4`)
256
261
  * LZMA (`:lzma`)
257
262
  * LZO (`:lzo`)
@@ -259,6 +264,14 @@ Supported value compressors:
259
264
  * QuickLZ (`:quicklz`)
260
265
  * Zlib (`:zlib`)
261
266
 
267
+ Supported encoders:
268
+
269
+ * Base64 (`:base64`)
270
+ * Url escape (`:escape`)
271
+ * Hexadecimal (`:hex`)
272
+ * QP (`:qp`)
273
+ * UUEncode (`:uuencode`)
274
+
262
275
  Special transformers:
263
276
 
264
277
  * Digests (MD5, Shas, CityHash, ...)
@@ -40,6 +40,7 @@ module Moneta
40
40
  autoload :LRUHash, 'moneta/adapters/lruhash'
41
41
  autoload :KyotoCabinet, 'moneta/adapters/kyotocabinet'
42
42
  autoload :LevelDB, 'moneta/adapters/leveldb'
43
+ autoload :LMDB, 'moneta/adapters/lmdb'
43
44
  autoload :LocalMemCache, 'moneta/adapters/localmemcache'
44
45
  autoload :Memcached, 'moneta/adapters/memcached'
45
46
  autoload :MemcachedDalli, 'moneta/adapters/memcached/dalli'
@@ -101,15 +102,13 @@ module Moneta
101
102
  transformer[:value] << (Symbol === compress ? compress : :zlib) if compress
102
103
  raise ArgumentError, 'Name must be Symbol' unless Symbol === name
103
104
  case name
104
- when :Sequel, :ActiveRecord, :Couch, :DataMapper
105
- # Sequel, DataMapper and AR accept only base64 keys and values
106
- # FIXME: Couch should work only with :marshal but this raises an error on 1.9
105
+ when :Sequel
106
+ # Sequel accept only base64 keys
107
107
  transformer[:key] << :base64
108
- transformer[:value] << :base64
109
- when :Riak, :RestClient
110
- # Riak accepts only utf-8 keys over the http interface
111
- # We use base64 encoding therefore.
108
+ when :ActiveRecord, :DataMapper, :Couch
109
+ # DataMapper and AR accept only base64 keys and values
112
110
  transformer[:key] << :base64
111
+ transformer[:value] << :base64
113
112
  when :PStore, :YAML, :Null
114
113
  # For PStore and YAML only the key has to be a string
115
114
  transformer.delete(:value) if transformer[:value] == [:marshal]
@@ -117,8 +116,8 @@ module Moneta
117
116
  # Use spreading hashes
118
117
  transformer[:key] << :md5 << :spread
119
118
  name = :File
120
- when :File
121
- # Use escaping
119
+ when :File, :Riak, :RestClient
120
+ # Use escaping for file and HTTP interfaces
122
121
  transformer[:key] << :escape
123
122
  end
124
123
  a = Adapters.const_get(name).new(options)
@@ -18,14 +18,20 @@ module Moneta
18
18
  # @option options [Integer] :port (9160) Server port
19
19
  # @option options [Integer] :expires Default expiration time
20
20
  # @option options [::Cassandra] :backend Use existing backend instance
21
+ # @option options Other options passed to `Cassandra#new`
21
22
  def initialize(options = {})
22
- self.default_expires = options[:expires]
23
- @cf = (options[:column_family] || 'moneta').to_sym
23
+ self.default_expires = options.delete(:expires)
24
+ @cf = (options.delete(:column_family) || 'moneta').to_sym
24
25
  if options[:backend]
25
26
  @backend = options[:backend]
26
27
  else
27
- keyspace = options[:keyspace] || 'moneta'
28
- @backend = ::Cassandra.new('system', "#{options[:host] || '127.0.0.1'}:#{options[:port] || 9160}")
28
+ keyspace = options.delete(:keyspace) || 'moneta'
29
+ options[:retries] ||= 3
30
+ options[:connect_timeout] ||= 10
31
+ options[:timeout] ||= 10
32
+ @backend = ::Cassandra.new('system',
33
+ "#{options[:host] || '127.0.0.1'}:#{options[:port] || 9160}",
34
+ options)
29
35
  unless @backend.keyspaces.include?(keyspace)
30
36
  cf_def = ::Cassandra::ColumnFamily.new(:keyspace => keyspace, :name => @cf.to_s)
31
37
  ks_def = ::Cassandra::Keyspace.new(:name => keyspace,
@@ -71,10 +77,6 @@ module Moneta
71
77
  def store(key, value, options = {})
72
78
  @backend.insert(@cf, key, {'value' => value}, :ttl => expires_value(options) || nil)
73
79
  value
74
- rescue
75
- # FIXME: We get spurious cassandra transport exceptions
76
- tries ||= 0
77
- (tries += 1) < 10 ? retry : raise
78
80
  end
79
81
 
80
82
  # (see Proxy#delete)
@@ -87,9 +89,7 @@ module Moneta
87
89
 
88
90
  # (see Proxy#clear)
89
91
  def clear(options = {})
90
- @backend.each_key(@cf) do |key|
91
- delete(key)
92
- end
92
+ @backend.clear_column_family!(@cf)
93
93
  self
94
94
  end
95
95
 
@@ -0,0 +1,93 @@
1
+ require 'lmdb'
2
+ require 'fileutils'
3
+
4
+ module Moneta
5
+ module Adapters
6
+ # LMDB backend
7
+ # @api public
8
+ class LMDB
9
+ include Defaults
10
+
11
+ supports :create, :increment
12
+ attr_reader :backend, :db
13
+
14
+ PUT_FLAGS = [:nooverwrite, :nodupdata, :current, :append, :appenddup]
15
+
16
+ # @param [Hash] options
17
+ # @option options [String] :dir Environment directory
18
+ # @option options [::LMDB::Environment] :backend Use existing backend instance
19
+ # @option options [String or nil] :db Database name
20
+ def initialize(options)
21
+ db = options.delete(:db)
22
+ @backend = options.delete(:backend) ||
23
+ begin
24
+ raise ArgumentError, 'Option :dir is required' unless dir = options.delete(:dir)
25
+ FileUtils.mkpath(dir)
26
+ ::LMDB.new(dir, options)
27
+ end
28
+
29
+ @db = @backend.database(db, :create => true)
30
+ end
31
+
32
+ # (see Proxy#key?)
33
+ def key?(key, options = {})
34
+ !@db.get(key).nil?
35
+ end
36
+
37
+ # (see Proxy#load)
38
+ def load(key, options = {})
39
+ @db.get(key)
40
+ end
41
+
42
+ # (see Proxy#store)
43
+ def store(key, value, options = {})
44
+ @db.put(key, value, Utils.only(options, *PUT_FLAGS))
45
+ value
46
+ end
47
+
48
+ # (see Proxy#delete)
49
+ def delete(key, options = {})
50
+ @backend.transaction do
51
+ if value = @db.get(key)
52
+ @db.delete(key)
53
+ value
54
+ end
55
+ end
56
+ end
57
+
58
+ # (see Proxy#clear)
59
+ def clear(options = {})
60
+ @db.clear
61
+ self
62
+ end
63
+
64
+ # (see Proxy#increment)
65
+ def increment(key, amount = 1, options = {})
66
+ @backend.transaction do
67
+ value = @db.get(key)
68
+ value = Utils.to_int(value) + amount
69
+ @db.put(key, value.to_s, Utils.only(options, *PUT_FLAGS))
70
+ value
71
+ end
72
+ end
73
+
74
+ # (see Defaults#create)
75
+ def create(key, value, options = {})
76
+ @backend.transaction do
77
+ if @db.get(key)
78
+ false
79
+ else
80
+ @db.put(key, value, Utils.only(options, *PUT_FLAGS))
81
+ true
82
+ end
83
+ end
84
+ end
85
+
86
+ # (see Proxy#close)
87
+ def close
88
+ @backend.close
89
+ nil
90
+ end
91
+ end
92
+ end
93
+ end
@@ -11,11 +11,13 @@ module Moneta
11
11
  include CreateSupport
12
12
 
13
13
  # @param [Hash] options
14
- # @option options [Integer] :max_size (1024000) Maximum total byte size of hash values
15
- # @option options [Integer] :max_count (10240) Maximum number of hash values
14
+ # @option options [Integer] :max_size (1024000) Maximum byte size of all values
15
+ # @option options [Integer] :max_value (options[:max_size]) Maximum byte size of one value
16
+ # @option options [Integer] :max_count (10240) Maximum number of values
16
17
  def initialize(options = {})
17
18
  @max_size = options[:max_size] || 1024000
18
19
  @max_count = options[:max_count] || 10240
20
+ @max_value = options[:max_value] || @max_size
19
21
  clear
20
22
  end
21
23
 
@@ -34,16 +36,20 @@ module Moneta
34
36
 
35
37
  # (see Proxy#store)
36
38
  def store(key, value, options = {})
37
- if entry = @entry[key]
38
- @size -= entry.value.bytesize
39
+ if value.bytesize > @max_value
40
+ delete(key)
39
41
  else
40
- @entry[key] = entry = Entry.new
41
- entry.key = key
42
+ if entry = @entry[key]
43
+ @size -= entry.value.bytesize
44
+ else
45
+ @entry[key] = entry = Entry.new
46
+ entry.key = key
47
+ end
48
+ entry.value = value
49
+ @size += entry.value.bytesize
50
+ entry.insert_after(@list)
51
+ delete(@list.prev.key) while @list.next != @list.prev && (@size > @max_size || @entry.size > @max_count)
42
52
  end
43
- entry.value = value
44
- @size += entry.value.bytesize
45
- entry.insert_after(@list)
46
- delete(@list.prev.key) while @list.next != @list.prev && (@size > @max_size || @entry.size > @max_count)
47
53
  value
48
54
  end
49
55
 
@@ -101,9 +101,8 @@ module Moneta
101
101
  key = to_binary(key)
102
102
  @collection.insert(value_to_doc(key, value, options))
103
103
  true
104
- rescue ::Mongo::OperationFailure
105
- # FIXME: This catches too many errors
106
- # it should only catch a not-unique-exception
104
+ rescue ::Mongo::OperationFailure => ex
105
+ raise if ex.error_code != 11000 # duplicate key error
107
106
  false
108
107
  end
109
108
 
@@ -47,9 +47,9 @@ module Moneta
47
47
  # (see Proxy#store)
48
48
  def store(key, value, options = {})
49
49
  begin
50
- @table.insert(:k => key, :v => value)
50
+ @table.insert(:k => key, :v => blob(value))
51
51
  rescue UniqueConstraintViolation
52
- @table.where(:k => key).update(:v => value)
52
+ @table.where(:k => key).update(:v => blob(value))
53
53
  end
54
54
  value
55
55
  rescue ::Sequel::DatabaseError
@@ -59,7 +59,7 @@ module Moneta
59
59
 
60
60
  # (see Proxy#store)
61
61
  def create(key, value, options = {})
62
- @table.insert(:k => key, :v => value)
62
+ @table.insert(:k => key, :v => blob(value))
63
63
  true
64
64
  rescue UniqueConstraintViolation
65
65
  false
@@ -71,10 +71,10 @@ module Moneta
71
71
  locked_table = @table.for_update
72
72
  if record = locked_table[:k => key]
73
73
  value = Utils.to_int(record[:v]) + amount
74
- locked_table.where(:k => key).update(:v => value.to_s)
74
+ locked_table.where(:k => key).update(:v => blob(value.to_s))
75
75
  value
76
76
  else
77
- locked_table.insert(:k => key, :v => amount.to_s)
77
+ locked_table.insert(:k => key, :v => blob(amount.to_s))
78
78
  amount
79
79
  end
80
80
  end
@@ -103,6 +103,13 @@ module Moneta
103
103
  @backend.disconnect
104
104
  nil
105
105
  end
106
+
107
+ private
108
+
109
+ # See https://github.com/jeremyevans/sequel/issues/715
110
+ def blob(s)
111
+ s.empty? ? '' : ::Sequel.blob(s)
112
+ end
106
113
  end
107
114
  end
108
115
  end
@@ -53,8 +53,7 @@ module Moneta
53
53
 
54
54
  # (see Proxy#load)
55
55
  def load(key, options = {})
56
- value = @cache.load(key, options)
57
- if value == nil
56
+ if options[:sync] || (value = @cache.load(key, options)) == nil
58
57
  value = @adapter.load(key, options)
59
58
  @cache.store(key, value, options) if value != nil
60
59
  end
@@ -39,6 +39,7 @@ module Moneta
39
39
  # @option options [Integer] :expires Update expiration time (See {Expires})
40
40
  # @option options [Boolean] :raw Raw access without value transformation (See {Transformer})
41
41
  # @option options [String] :prefix Prefix key (See {Transformer})
42
+ # @option options [Boolean] :sync Synchronized load ({Cache} reloads from adapter, {Adapters::Daybreak} syncs with file)
42
43
  # @option options Other options as defined by the adapters or middleware
43
44
  # @return [Object] value
44
45
  # @api public
@@ -31,11 +31,10 @@ module Moneta
31
31
  # @param [Number] wait Sleep time between tries to acquire lock
32
32
  # @return [Boolean] true if the lock was aquired
33
33
  def enter(timeout = nil, wait = 0.01)
34
- total = 0
35
- while !timeout || total < timeout
34
+ time_at_timeout = Time.now + timeout if timeout
35
+ while !timeout || Time.now < time_at_timeout
36
36
  return true if try_enter
37
37
  sleep(wait)
38
- total += wait
39
38
  end
40
39
  false
41
40
  end
@@ -6,10 +6,11 @@ module Moneta
6
6
  :bencode => [ :serialize, '::BEncode.load(%s)', '::BEncode.dump(%s)', 'bencode' ],
7
7
  :bert => [ :serialize, '::BERT.decode(%s)', '::BERT.encode(%s)', 'bert' ],
8
8
  :bson => [ :serialize, "::BSON.deserialize(%s)['v']", "::BSON.serialize('v'=>%s).to_s", 'bson' ],
9
- :json => [ :serialize, '::MultiJson.load(%s).first', '::MultiJson.dump([%s])', 'multi_json' ],
9
+ :json => [ :serialize, '::MultiJson.load(%s)', '::MultiJson.dump(%s)', 'multi_json' ],
10
10
  :marshal => [ :serialize, '::Marshal.load(%s)', '::Marshal.dump(%s)' ],
11
11
  :msgpack => [ :serialize, '::MessagePack.unpack(%s)', '::MessagePack.pack(%s)', 'msgpack' ],
12
12
  :ox => [ :serialize, '::Ox.parse_obj(%s)', '::Ox.dump(%s)', 'ox' ],
13
+ :php => [ :serialize, '::PHP.unserialize(%s)', '::PHP.serialize(%s)', 'php_serialize' ],
13
14
  :tnet => [ :serialize, '::TNetstring.parse(%s).first', '::TNetstring.dump(%s)', 'tnetstring' ],
14
15
  :yaml => [ :serialize, '::YAML.load(%s)', '::YAML.dump(%s)', 'yaml' ],
15
16
  :bzip2 => [ :compress, '::Bzip2.uncompress(%s)', '::Bzip2.compress(%s)', 'bzip2' ],
@@ -19,12 +20,13 @@ module Moneta
19
20
  :snappy => [ :compress, '::Snappy.inflate(%s)', '::Snappy.deflate(%s)', 'snappy' ],
20
21
  :quicklz => [ :compress, '::QuickLZ.decompress(%s)', '::QuickLZ.compress(%s)', 'qlzruby' ],
21
22
  :zlib => [ :compress, '::Zlib::Inflate.inflate(%s)', '::Zlib::Deflate.deflate(%s)', 'zlib' ],
22
- :qp => [ :encode, "%s.unpack('M').first", "[%s].pack('M')" ],
23
- :uuencode => [ :encode, "%s.unpack('u').first", "[%s].pack('u')" ],
24
23
  :base64 => RUBY_VERSION > '1.9' ?
25
24
  [ :encode, "%s.unpack('m0').first", "[%s].pack('m0')" ] :
26
25
  [ :encode, "%s.unpack('m').first", "[%s].pack('m').gsub(\"\n\", '')" ],
27
26
  :escape => [ :encode, 'Helper.unescape(%s)', 'Helper.escape(%s)' ],
27
+ :hex => [ :encode, "[%s].pack('H*')", "%s.unpack('H*').first" ],
28
+ :qp => [ :encode, "%s.unpack('M').first", "[%s].pack('M')" ],
29
+ :uuencode => [ :encode, "%s.unpack('u').first", "[%s].pack('u')" ],
28
30
  :hmac => [ :hmac, 'Helper.hmacverify(%s, options[:secret] || @secret)',
29
31
  'Helper.hmacsign(%s, options[:secret] || @secret)', 'openssl' ],
30
32
  :truncate => [ :truncate, nil, 'Helper.truncate(%s, @maxlen)', 'digest/md5' ],