any_cache 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +12 -0
- data/CHANGELOG.md +10 -0
- data/README.md +267 -18
- data/Rakefile +10 -0
- data/any_cache.gemspec +2 -2
- data/bin/rspec +15 -5
- data/gemfiles/active_support_with_dalli.gemfile +8 -0
- data/lib/any_cache/adapters/active_support_file_store.rb +1 -2
- data/lib/any_cache/adapters/active_support_mem_cache_store.rb +163 -0
- data/lib/any_cache/adapters/active_support_memory_store.rb +1 -2
- data/lib/any_cache/adapters/active_support_naive_store.rb +30 -0
- data/lib/any_cache/adapters/active_support_redis_cache_store.rb +34 -10
- data/lib/any_cache/adapters/basic.rb +20 -0
- data/lib/any_cache/adapters/dalli.rb +30 -2
- data/lib/any_cache/adapters/delegator.rb +6 -2
- data/lib/any_cache/adapters/redis.rb +30 -4
- data/lib/any_cache/adapters/redis_store.rb +6 -3
- data/lib/any_cache/adapters.rb +4 -2
- data/lib/any_cache/drivers/active_support_file_store.rb +26 -0
- data/lib/any_cache/drivers/active_support_mem_cache_store.rb +25 -0
- data/lib/any_cache/drivers/active_support_memory_store.rb +26 -0
- data/lib/any_cache/drivers/active_support_redis_cache_store.rb +27 -0
- data/lib/any_cache/drivers/dalli.rb +25 -0
- data/lib/any_cache/drivers/redis.rb +25 -0
- data/lib/any_cache/drivers/redis_store.rb +25 -0
- data/lib/any_cache/drivers.rb +45 -0
- data/lib/any_cache/version.rb +1 -1
- data/lib/any_cache.rb +48 -3
- metadata +28 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb955a7841f5f154dd3a18dcc911333edcf3f9ccc7564c84a8165022cb64e201
|
4
|
+
data.tar.gz: 85ff1e78b433f11a8b870c49fd012b984491873923be153abf6117c57b757a49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aaf92352c50ff3a15610214136f4c8b586786548ee384ec46c377b8f055318060417b0cf14ce9c4522e551b3891a2fe35546570f7ba7bef050faee921b4acbbe
|
7
|
+
data.tar.gz: 14c37f9ab0c5319408e6366c4bcafacf3eb0f220b621fb7c68325ceac0bed3173953003e1ba052888788e875e98390d21e95588b9d82cddcef361a9b630e51ff
|
data/.travis.yml
CHANGED
@@ -82,3 +82,15 @@ matrix:
|
|
82
82
|
- rvm: ruby-head
|
83
83
|
gemfile: gemfiles/redis_store.gemfile
|
84
84
|
env: TEST_REDIS_CACHE=true
|
85
|
+
- rvm: 2.3.7
|
86
|
+
gemfile: gemfiles/active_support_with_dalli.gemfile
|
87
|
+
env: TEST_AS_MEM_CACHE_STORE_CACHE=true
|
88
|
+
- rvm: 2.4.4
|
89
|
+
gemfile: gemfiles/active_support_with_dalli.gemfile
|
90
|
+
env: TEST_AS_MEM_CACHE_STORE_CACHE=true
|
91
|
+
- rvm: 2.5.1
|
92
|
+
gemfile: gemfiles/active_support_with_dalli.gemfile
|
93
|
+
env: TEST_AS_MEM_CACHE_STORE_CACHE=true
|
94
|
+
- rvm: ruby-head
|
95
|
+
gemfile: gemfiles/active_support_with_dalli.gemfile
|
96
|
+
env: TEST_AS_MEM_CACHE_STORE_CACHE=true
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [0.2.0] - 2018-09-03
|
5
|
+
- fetching operation `AnyCache#fetch(key, force:, expires_in:, &block)`
|
6
|
+
- fetches data from the cache using the given key;
|
7
|
+
- if a block has been passed and data with the given key does not exist -
|
8
|
+
that block will be called and the return value will be written to the cache;
|
9
|
+
- existence operation `AnyCache#exist?(key)` - determine if an entry exists or not;
|
10
|
+
- support for `ActiveSupport::Cache::MemCacheStore`;
|
11
|
+
- configuration layer `AnyCache.configure`: an ability to choose and configure a necessary cache client
|
12
|
+
without any explicit client object instantiation (client object will be instantiated implicitly);
|
13
|
+
|
4
14
|
## [0.1.0] - 2018-08-26
|
5
15
|
- Release :)
|
data/README.md
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
# AnyCache · [](https://badge.fury.io/rb/any_cache) [](https://travis-ci.org/0exp/any_cache) [](https://coveralls.io/github/0exp/any_cache)
|
2
2
|
|
3
3
|
AnyCache - a simplest cache wrapper that provides a minimalistic generic interface for all well-known cache storages and includes a minimal set of necessary operations:
|
4
|
-
`read`, `write`, `delete`, `expire`, `persist`, `clear`, `increment`, `decrement`.
|
4
|
+
`fetch`, `read`, `write`, `delete`, `expire`, `persist`, `exist?`, `clear`, `increment`, `decrement`.
|
5
5
|
|
6
6
|
Supported clients:
|
7
7
|
|
8
8
|
- `Redis` ([gem redis](https://github.com/redis/redis-rb)) ([redis storage](https://redis.io/))
|
9
9
|
- `Redis::Store` ([gem redis-store](https://github.com/redis-store/redis-store)) ([redis storage](https://redis.io/))
|
10
10
|
- `Dalli::Client` ([gem dalli](https://github.com/petergoldstein/dalli)) ([memcached storage](https://memcached.org/))
|
11
|
+
- `ActiveSupport::Cache::RedisCacheStore` ([gem activesupport](https://github.com/rails/rails/blob/master/activesupport/lib/active_support/cache/redis_cache_store.rb)) ([redis cache storage](https://api.rubyonrails.org/classes/ActiveSupport/Cache/RedisCacheStore.html))
|
12
|
+
- `ActiveSupport::Cache::MemCacheStore` ([gem activesupport](https://github.com/rails/rails/blob/master/activesupport/lib/active_support/cache/mem_cache_store.rb)) ([memcache storage](https://api.rubyonrails.org/classes/ActiveSupport/Cache/MemCacheStore.html))
|
11
13
|
- `ActiveSupport::Cache::FileStore` ([gem activesupport](https://github.com/rails/rails/blob/master/activesupport/lib/active_support/cache/file_store.rb)) ([file storage](https://api.rubyonrails.org/classes/ActiveSupport/Cache/FileStore.html))
|
12
14
|
- `ActiveSupport::Cache::MemoryStore` ([gem activesupport](https://github.com/rails/rails/blob/master/activesupport/lib/active_support/cache/memory_store.rb)) ([in memory storage](https://api.rubyonrails.org/classes/ActiveSupport/Cache/MemoryStore.html))
|
13
|
-
- `ActiveSupport::Cache::RedisCacheStore` ([gem activesupport](https://github.com/rails/rails/blob/master/activesupport/lib/active_support/cache/redis_cache_store.rb)) ([redis cache storage](https://api.rubyonrails.org/classes/ActiveSupport/Cache/RedisCacheStore.html))
|
14
15
|
|
15
16
|
---
|
16
17
|
|
@@ -35,7 +36,19 @@ require 'any_cache'
|
|
35
36
|
## Usage / Table of Contents
|
36
37
|
|
37
38
|
- [Creation](#creation)
|
38
|
-
-
|
39
|
+
- [Manual creation](#manual-creation)
|
40
|
+
- [Config-based creation](#config-based-creation)
|
41
|
+
- [AnyCache with Redis](#anycache-with-redis)
|
42
|
+
- [AnyCache with Redis::Store](#anycache-with-redisstore)
|
43
|
+
- [AnyCache with Dalli::Client](#anycache-with-dalliclient)
|
44
|
+
- [AnyCache with ActiveSupport::Cache::RedisCacheStore](#anycache-with-activesupportcacherediscachestore)
|
45
|
+
- [AnyCache with ActiveSupport::Cache::MemCacheStore](#anycache-with-activesupportcachememcachestore)
|
46
|
+
- [AnyCache with ActiveSupport::Cache::FileStore](#anycache-with-activesupportcachefilestore)
|
47
|
+
- [AnyCache with ActiveSupport::Cache::MemoryStore](#anycache-with-activesupportcachememorystore)
|
48
|
+
- [Many cache storages](#many-cache-storages)
|
49
|
+
- [Custom cache clients](#custom-cache-clients)
|
50
|
+
- [Operations](#operations)
|
51
|
+
- [Fetch](#fetch)
|
39
52
|
- [Read](#read)
|
40
53
|
- [Write](#write)
|
41
54
|
- [Delete](#delete)
|
@@ -43,6 +56,7 @@ require 'any_cache'
|
|
43
56
|
- [Decrement](#decrement)
|
44
57
|
- [Expire](#expire)
|
45
58
|
- [Persist](#persist)
|
59
|
+
- [Existence](#existence)
|
46
60
|
- [Clear](#clear)
|
47
61
|
|
48
62
|
---
|
@@ -51,16 +65,25 @@ require 'any_cache'
|
|
51
65
|
|
52
66
|
To instantiate AnyCache instance you have to provide a client.
|
53
67
|
Client - an independent driver that works with a corresponding cache storage (external dependency).
|
68
|
+
|
54
69
|
Supported clients:
|
55
70
|
|
56
71
|
- `Redis`
|
57
72
|
- `Redis::Store`
|
58
73
|
- `Dalli::Client`
|
59
74
|
- `ActiveSupport::Cache::RedisCacheStore`
|
75
|
+
- `ActiveSupport::Cache::MemCacheStore`
|
60
76
|
- `ActiveSupport::Cache::FileStore`
|
61
77
|
- `ActiveSupport::Cache::MemoryStore`
|
62
78
|
|
63
|
-
`AnyCache`
|
79
|
+
`AnyCache` can be instantiated by two ways:
|
80
|
+
|
81
|
+
- with explicit client object instantiated manually ([read](#manual-creation));
|
82
|
+
- via configuration ([read](#config-based-creation));
|
83
|
+
|
84
|
+
#### Manual creation
|
85
|
+
|
86
|
+
Custom instantiation with explicit client objects:
|
64
87
|
|
65
88
|
```ruby
|
66
89
|
# 1) create client object
|
@@ -71,6 +94,8 @@ client = Redis::Store.new(...)
|
|
71
94
|
client = Dalli::Client.new(...)
|
72
95
|
# -- or --
|
73
96
|
client = ActiveSupport::Cache::RedisCacheStore.new(...)
|
97
|
+
# --- or ---
|
98
|
+
client = ActiveSupport::Cache::MemCacheStore.new(...)
|
74
99
|
# -- or --
|
75
100
|
client = ActiveSupport::Cache::FileStore.new(...)
|
76
101
|
# -- or --
|
@@ -80,22 +105,237 @@ client = ActiveSupport::Cache::MemoryStore.new(...)
|
|
80
105
|
any_cache = AnyCache.build(client) # => <AnyCache:0x00007f990527f268 ...>
|
81
106
|
```
|
82
107
|
|
108
|
+
#### Config-based creation
|
109
|
+
|
110
|
+
You can configure `AnyCache` globally or create subclasses and configure each of them. After that
|
111
|
+
storage instantiation works via `.build` method without explicit attributes.
|
112
|
+
|
113
|
+
- `AnyCache.configure` is used for configuration;
|
114
|
+
- `config.driver` is used for determine which client should be used;
|
115
|
+
- `config.__driver_name__.options` stores client-related options;
|
116
|
+
|
117
|
+
Supported drivers:
|
118
|
+
|
119
|
+
- `:redis` - [Redis](#anycache-with-redis);
|
120
|
+
- `:redis_tore` - [Redis::Client](#anycache-with-redisstore);
|
121
|
+
- `:dalli` - [Dalli::Client](#anycache-with-dalliclient);
|
122
|
+
- `:as_redis_cache_store` - [ActiveSupport::Cache::RedisCacheStore](#anycache-with-activesupportcacherediscachestore);
|
123
|
+
- `:as_mem_cache_store` - [ActiveSupport::Cache::MemCacheStore](#anycache-with-activesupportcachememcachestore);
|
124
|
+
- `:as_file_store` - [ActiveSupport::Cache::FileStore](#anycache-with-activesupportcachefilestore);
|
125
|
+
- `:as_memory_store` - [ActiveSupport::Cache::MemoryStore](#anycache-with-activesupportcachememorystore);
|
126
|
+
|
127
|
+
##### `AnyCache` with `Redis`:
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
require 'redis'
|
131
|
+
require 'any_cache'
|
132
|
+
|
133
|
+
AnyCache.configure do |conf|
|
134
|
+
conf.driver = :redis
|
135
|
+
conf.redis.options = { ... } # Redis-related options
|
136
|
+
end
|
137
|
+
|
138
|
+
AnyCache.build
|
139
|
+
```
|
140
|
+
|
141
|
+
##### `AnyCache` with `Redis::Store`:
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
require 'redis-store'
|
145
|
+
require 'any_cache'
|
146
|
+
|
147
|
+
AnyCache.configure do |conf|
|
148
|
+
conf.driver = :redis_store
|
149
|
+
conf.redis_store.options = { ... } # Redis::Store-related options
|
150
|
+
end
|
151
|
+
|
152
|
+
AnyCache.build
|
153
|
+
```
|
154
|
+
|
155
|
+
##### `AnyCache` with `Dalli::Client`:
|
156
|
+
|
157
|
+
```ruby
|
158
|
+
require 'dalli'
|
159
|
+
require 'any_cache'
|
160
|
+
|
161
|
+
AnyCache.configure do |conf|
|
162
|
+
conf.driver = :dalli
|
163
|
+
conf.dalli.servers = ... # string or array of strings
|
164
|
+
conf.dalli.options = { ... } # Dalli::Client-related options
|
165
|
+
end
|
166
|
+
|
167
|
+
AnyCache.build
|
168
|
+
```
|
169
|
+
|
170
|
+
##### `AnyCache` with `ActiveSupport::Cache::RedisCacheStore`:
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
require 'active_support'
|
174
|
+
require 'any_cache'
|
175
|
+
|
176
|
+
AnyCache.configure do |conf|
|
177
|
+
conf.driver = :as_redis_cache_store
|
178
|
+
conf.as_redis_cache_store.options = { ... } # ActiveSupport::Cache::RedisCacheStore-related options
|
179
|
+
end
|
180
|
+
|
181
|
+
AnyCache.build
|
182
|
+
```
|
183
|
+
|
184
|
+
##### `AnyCache` with `ActiveSupport::Cache::MemCacheStore`:
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
require 'active_support'
|
188
|
+
require 'any_cache'
|
189
|
+
|
190
|
+
AnyCache.configure do |conf|
|
191
|
+
conf.driver = :as_mem_cache_store
|
192
|
+
conf.as_memory_store.servers = ... # string or array of strings
|
193
|
+
conf.as_memory_store.options = { ... } # ActiveSupport::Cache::MemCacheStore-related options
|
194
|
+
end
|
195
|
+
|
196
|
+
AnyCache.build
|
197
|
+
```
|
198
|
+
|
199
|
+
##### `AnyCache` with `ActiveSupport::Cache::FileStore`:
|
200
|
+
|
201
|
+
```ruby
|
202
|
+
require 'active_support'
|
203
|
+
require 'any_cache'
|
204
|
+
|
205
|
+
AnyCache.configure do |conf|
|
206
|
+
conf.driver = :as_file_store
|
207
|
+
conf.as_file_store.cache_path = '/path/to/cache'
|
208
|
+
conf.as_file_store.options = { ... } # ActiveSupport::Cache::FileStore-related options
|
209
|
+
end
|
210
|
+
|
211
|
+
AnyCache.build
|
212
|
+
```
|
213
|
+
|
214
|
+
##### `AnyCache` with `ActiveSupport::Cache::MemoryStore`:
|
215
|
+
|
216
|
+
```ruby
|
217
|
+
require 'activesupport'
|
218
|
+
require 'any_cache'
|
219
|
+
|
220
|
+
AnyCache.configure do |conf|
|
221
|
+
conf.driver = :as_memory_store
|
222
|
+
conf.as_memory_store.options = { ... } # ActiveSupport::Cache::MemoryStore-related options
|
223
|
+
end
|
224
|
+
|
225
|
+
AnyCache.build
|
226
|
+
```
|
227
|
+
|
228
|
+
#### Many cache storages
|
229
|
+
|
230
|
+
You can inherit `AnyCache` class and create and configure as many cache storages as you want:
|
231
|
+
|
232
|
+
```ruby
|
233
|
+
class RedisCache < AnyCache
|
234
|
+
configure do |conf|
|
235
|
+
conf.driver = :redis
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
class DalliCache < AnyCache
|
240
|
+
configure do |conf|
|
241
|
+
conf.driver = :dalli
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
redis_cache = RedisCache.build
|
246
|
+
dalli_cache = DalliCache.build
|
247
|
+
```
|
248
|
+
|
249
|
+
#### Custom cache clients
|
250
|
+
|
83
251
|
If you want to use your own cache client implementation, you should provide an object that responds to:
|
84
252
|
|
253
|
+
- `#fetch(*key, [**options])` ([doc](#fetch))
|
85
254
|
- `#read(key, [**options])` ([doc](#read))
|
86
255
|
- `#write(key, value, [**options])` ([doc](#write))
|
87
256
|
- `#delete(key, [**options])` ([doc](#delete))
|
88
257
|
- `#increment(key, amount, [**options])` ([doc](#increment))
|
89
|
-
- `#
|
258
|
+
- `#decrement(key, amount, [**options])` ([doc](#decrement))
|
90
259
|
- `#expire(key, [**options])` ([doc](#expire))
|
91
260
|
- `#persist(key, [**options])` ([doc](#persist))
|
261
|
+
- `#exist?(key, [**options])` ([doc](#existence))
|
92
262
|
- `#clear([**options])` ([doc](#clear))
|
93
263
|
|
264
|
+
```ruby
|
265
|
+
class MyCacheClient
|
266
|
+
# ...
|
267
|
+
|
268
|
+
def read(key, **)
|
269
|
+
# ...
|
270
|
+
end
|
271
|
+
|
272
|
+
def write(key, value, **)
|
273
|
+
# ...
|
274
|
+
end
|
275
|
+
|
276
|
+
# ...
|
277
|
+
end
|
278
|
+
|
279
|
+
AnyCache.build(MyCacheClient.new)
|
280
|
+
```
|
281
|
+
|
282
|
+
## Operations
|
283
|
+
|
284
|
+
`AnyCache` provides a following operation set:
|
285
|
+
|
286
|
+
- [fetch](#fetch)
|
287
|
+
- [read](#read)
|
288
|
+
- [write](#write)
|
289
|
+
- [delete](#delete)
|
290
|
+
- [increment](#increment)
|
291
|
+
- [decrement](#decrement)
|
292
|
+
- [expire](#expire)
|
293
|
+
- [persist](#persist)
|
294
|
+
- [clear](#clear)
|
295
|
+
- [exist?](#existence)
|
296
|
+
|
297
|
+
---
|
298
|
+
|
299
|
+
### Fetch
|
300
|
+
|
301
|
+
- `AnyCache#fetch(key, [force:], [expires_in:], [&block])`
|
302
|
+
- works in `ActiveSupport::Cache::Store#fetch`-manner;
|
303
|
+
- fetches data from the cache, using the given key;
|
304
|
+
- if there is data in the cache with the given key, then that data is returned;
|
305
|
+
- if there is no such data in the cache (a cache miss), then nil will be returned:
|
306
|
+
- if a block has been passed, that block will be passed the key and executed in the event of a cache miss;
|
307
|
+
- the return value of the block will be written to the cache under the given cache key, and that return value will be returned;
|
308
|
+
|
309
|
+
```ruby
|
310
|
+
# --- entry exists ---
|
311
|
+
any_cache.fetch("data") # => "some_data"
|
312
|
+
any_cache.fetch("data") { "new_data" } # => "some_data"
|
313
|
+
|
314
|
+
# --- entry does not exist ---
|
315
|
+
any_cache.fetch("data") # => nil
|
316
|
+
any_cache.fetch("data") { "new_data" } # => "new_data"
|
317
|
+
any_cache.fetch("data") # => "new_data"
|
318
|
+
|
319
|
+
# --- new entry with expiration time ---
|
320
|
+
any_cache.fetch("data") # => nil
|
321
|
+
any_cache.fetch("data", expires_in: 8) { "new_data" } # => "new_data"
|
322
|
+
any_cache.fetch("data") # => "new_data"
|
323
|
+
# ...sleep 8 seconds...
|
324
|
+
any_cache.fetch("data") # => nil
|
325
|
+
|
326
|
+
# --- force update/rewrite ---
|
327
|
+
any_cache.fetch("data") # => "some_data"
|
328
|
+
any_cache.fetch("data", expires_in: 8, force: true) { "new_data" } # => "new_data"
|
329
|
+
any_cache.fetch("data") # => "new_data"
|
330
|
+
# ...sleep 8 seconds...
|
331
|
+
any_cache.fetch("data") # => nil
|
332
|
+
```
|
333
|
+
|
94
334
|
---
|
95
335
|
|
96
336
|
### Read
|
97
337
|
|
98
|
-
- `AnyCache#read(key)` - get entry value from cache storage
|
338
|
+
- `AnyCache#read(key)` - get an entry value from the cache storage
|
99
339
|
|
100
340
|
```ruby
|
101
341
|
# --- entry exists ---
|
@@ -109,7 +349,7 @@ any_cache.read("data") # => nil
|
|
109
349
|
|
110
350
|
### Write
|
111
351
|
|
112
|
-
- `AnyCache#write(key, value, [expires_in:])` - write new entry to cache storage
|
352
|
+
- `AnyCache#write(key, value, [expires_in:])` - write a new entry to the cache storage
|
113
353
|
|
114
354
|
```ruby
|
115
355
|
# --- permanent entry ---
|
@@ -123,7 +363,7 @@ any_cache.write("data", 123, expires_in: 60)
|
|
123
363
|
|
124
364
|
### Delete
|
125
365
|
|
126
|
-
- `AnyCache#delete(key)` - remove entry from cache storage
|
366
|
+
- `AnyCache#delete(key)` - remove entry from the cache storage
|
127
367
|
|
128
368
|
```ruby
|
129
369
|
any_cache.delete("data")
|
@@ -133,8 +373,8 @@ any_cache.delete("data")
|
|
133
373
|
|
134
374
|
### Increment
|
135
375
|
|
136
|
-
- `AnyCache#increment(key, amount = 1, [expires_in:])` - increment entry's value by
|
137
|
-
and set new expiration time if needed
|
376
|
+
- `AnyCache#increment(key, amount = 1, [expires_in:])` - increment entry's value by the given amount
|
377
|
+
and set the new expiration time if needed
|
138
378
|
|
139
379
|
```ruby
|
140
380
|
# --- increment existing entry ---
|
@@ -157,8 +397,8 @@ any_cache.increment("another_data", 5, expires_in: 5) # => 5
|
|
157
397
|
|
158
398
|
### Decrement
|
159
399
|
|
160
|
-
- `AnyCache#decrement(key, amount = 1, [expires_in:])` - decrement entry's value by
|
161
|
-
and set new expiration time if needed
|
400
|
+
- `AnyCache#decrement(key, amount = 1, [expires_in:])` - decrement entry's value by the given amount
|
401
|
+
and set the new expiration time if needed
|
162
402
|
|
163
403
|
```ruby
|
164
404
|
# --- decrement existing entry ---
|
@@ -207,6 +447,20 @@ any_cache.persist("data")
|
|
207
447
|
|
208
448
|
---
|
209
449
|
|
450
|
+
### Existence
|
451
|
+
|
452
|
+
- `AnyCache#exist?(key)` - determine if an entry exists
|
453
|
+
|
454
|
+
```ruby
|
455
|
+
# --- entry exists ---
|
456
|
+
any_cache.exist?("data") # => true
|
457
|
+
|
458
|
+
# --- entry does not exist ---
|
459
|
+
any_cache.exist?("another-data") # => false
|
460
|
+
```
|
461
|
+
|
462
|
+
---
|
463
|
+
|
210
464
|
### Clear
|
211
465
|
|
212
466
|
- `AnyCache#clear()` - clear cache database
|
@@ -239,16 +493,11 @@ bin/rspec --test-dalli # run specs with Dalli::Client
|
|
239
493
|
bin/rspec --test-as-file-store # run specs with ActiveSupport::Cache::FileStore
|
240
494
|
bin/rspec --test-as-memory-store # run specs with ActiveSupport::Cache::MemoryStore
|
241
495
|
bin/rspec --test-as-redis-cache-store # run specs with ActiveSupport::Cache::RedisCacheStore
|
496
|
+
bin/rspec --test-as-mem-cache-store # run specs with ActiveSupport::Cache::MemCacheStore
|
242
497
|
```
|
243
498
|
|
244
499
|
---
|
245
500
|
|
246
|
-
## Roadmap
|
247
|
-
|
248
|
-
- configuration layer with ability to instantiate cache clients implicitly
|
249
|
-
|
250
|
-
---
|
251
|
-
|
252
501
|
## Contributing
|
253
502
|
|
254
503
|
- Fork it (https://github.com/0exp/any_cache/fork)
|
data/Rakefile
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
require 'bundler/gem_tasks'
|
4
4
|
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop'
|
6
|
+
require 'rubocop-rspec'
|
7
|
+
require 'rubocop/rake_task'
|
8
|
+
|
9
|
+
RuboCop::RakeTask.new(:rubocop) do |t|
|
10
|
+
config_path = File.expand_path(File.join('.rubocop.yml'), __dir__)
|
11
|
+
|
12
|
+
t.options = ['--config', config_path]
|
13
|
+
t.requires << 'rubocop-rspec'
|
14
|
+
end
|
5
15
|
|
6
16
|
RSpec::Core::RakeTask.new(:rspec)
|
7
17
|
|
data/any_cache.gemspec
CHANGED
@@ -28,12 +28,12 @@ Gem::Specification.new do |spec|
|
|
28
28
|
end
|
29
29
|
|
30
30
|
spec.add_dependency 'concurrent-ruby', '~> 1.0'
|
31
|
+
spec.add_dependency 'qonfig', '~> 0.6'
|
31
32
|
|
32
33
|
spec.add_development_dependency 'coveralls', '~> 0.8'
|
33
34
|
spec.add_development_dependency 'simplecov', '~> 0.16'
|
34
|
-
spec.add_development_dependency 'armitage-rubocop', '~> 0.
|
35
|
+
spec.add_development_dependency 'armitage-rubocop', '~> 0.7'
|
35
36
|
spec.add_development_dependency 'rspec', '~> 3.8'
|
36
|
-
spec.add_development_dependency 'qonfig', '~> 0.6'
|
37
37
|
|
38
38
|
spec.add_development_dependency 'bundler'
|
39
39
|
spec.add_development_dependency 'rake'
|
data/bin/rspec
CHANGED
@@ -8,18 +8,16 @@ module AnyCacheSpecRunner
|
|
8
8
|
extend self
|
9
9
|
|
10
10
|
def expand_gemfile_path(gemfile_name)
|
11
|
-
File.expand_path(
|
12
|
-
File.join('..', '..', 'gemfiles', gemfile_name),
|
13
|
-
Pathname.new(__FILE__).realpath
|
14
|
-
)
|
11
|
+
File.expand_path(File.join('..', 'gemfiles', gemfile_name), __dir__)
|
15
12
|
end
|
16
13
|
|
17
14
|
GEMFILES = {
|
18
15
|
redis: expand_gemfile_path('redis.gemfile'),
|
19
16
|
redis_store: expand_gemfile_path('redis_store.gemfile'),
|
20
17
|
dalli: expand_gemfile_path('dalli.gemfile'),
|
18
|
+
active_support: expand_gemfile_path('active_support.gemfile'),
|
21
19
|
active_support_with_redis: expand_gemfile_path('active_support_with_redis.gemfile'),
|
22
|
-
|
20
|
+
active_support_with_dalli: expand_gemfile_path('active_support_with_dalli.gemfile')
|
23
21
|
}.freeze
|
24
22
|
|
25
23
|
# rubocop:disable Metrics/MethodLength, Metrics/BlockLength
|
@@ -57,6 +55,11 @@ module AnyCacheSpecRunner
|
|
57
55
|
'Run specs with ActiveSupport::Cache::MemoryStore cache storage'
|
58
56
|
) { run_as_memory_store_cache_specs! }
|
59
57
|
|
58
|
+
opts.on(
|
59
|
+
'--test-as-mem-cache-store',
|
60
|
+
'Run specs with ActiveSupport::Cache::MemCacheStore cache storage'
|
61
|
+
) { run_as_mem_cache_store_cache_specs! }
|
62
|
+
|
60
63
|
opts.on(
|
61
64
|
'-h', '--help',
|
62
65
|
'Show this message'
|
@@ -109,6 +112,13 @@ module AnyCacheSpecRunner
|
|
109
112
|
run_tests!
|
110
113
|
end
|
111
114
|
|
115
|
+
def run_as_mem_cache_store_cache_specs!
|
116
|
+
ENV['TEST_AS_MEM_CACHE_STORE_CACHE'] = 'true'
|
117
|
+
ENV['BUNDLE_GEMFILE'] = GEMFILES[:active_support_with_dalli]
|
118
|
+
|
119
|
+
run_tests!
|
120
|
+
end
|
121
|
+
|
112
122
|
def run_tests!
|
113
123
|
require 'rubygems'
|
114
124
|
require 'bundler/setup'
|
@@ -18,8 +18,7 @@ module AnyCache::Adapters
|
|
18
18
|
# @api private
|
19
19
|
# @since 0.1.0
|
20
20
|
def supported_driver?(driver)
|
21
|
-
|
22
|
-
driver.is_a?(::ActiveSupport::Cache::FileStore)
|
21
|
+
AnyCache::Drivers::ActiveSupportFileStore.supported_source?(driver)
|
23
22
|
end
|
24
23
|
end
|
25
24
|
end
|