any_cache 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +6 -2
- data/.rspec +1 -1
- data/.rubocop.yml +18 -0
- data/.travis.yml +83 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile +4 -2
- data/README.md +241 -18
- data/Rakefile +6 -4
- data/any_cache.gemspec +21 -7
- data/bin/console +5 -11
- data/bin/rspec +119 -0
- data/gemfiles/active_support.gemfile +7 -0
- data/gemfiles/active_support_with_redis.gemfile +8 -0
- data/gemfiles/dalli.gemfile +7 -0
- data/gemfiles/redis.gemfile +7 -0
- data/gemfiles/redis_store.gemfile +7 -0
- data/lib/any_cache.rb +49 -3
- data/lib/any_cache/adapters.rb +40 -0
- data/lib/any_cache/adapters/active_support_file_store.rb +26 -0
- data/lib/any_cache/adapters/active_support_file_store/decrement.rb +10 -0
- data/lib/any_cache/adapters/active_support_file_store/expire.rb +10 -0
- data/lib/any_cache/adapters/active_support_file_store/fetching.rb +28 -0
- data/lib/any_cache/adapters/active_support_file_store/increment.rb +10 -0
- data/lib/any_cache/adapters/active_support_file_store/operation.rb +10 -0
- data/lib/any_cache/adapters/active_support_file_store/persist.rb +10 -0
- data/lib/any_cache/adapters/active_support_memory_store.rb +26 -0
- data/lib/any_cache/adapters/active_support_memory_store/decrement.rb +10 -0
- data/lib/any_cache/adapters/active_support_memory_store/expire.rb +10 -0
- data/lib/any_cache/adapters/active_support_memory_store/fetching.rb +16 -0
- data/lib/any_cache/adapters/active_support_memory_store/increment.rb +10 -0
- data/lib/any_cache/adapters/active_support_memory_store/operation.rb +10 -0
- data/lib/any_cache/adapters/active_support_memory_store/persist.rb +10 -0
- data/lib/any_cache/adapters/active_support_naive_store.rb +150 -0
- data/lib/any_cache/adapters/active_support_naive_store/decrement.rb +72 -0
- data/lib/any_cache/adapters/active_support_naive_store/expire.rb +25 -0
- data/lib/any_cache/adapters/active_support_naive_store/increment.rb +71 -0
- data/lib/any_cache/adapters/active_support_naive_store/operation.rb +64 -0
- data/lib/any_cache/adapters/active_support_naive_store/persist.rb +22 -0
- data/lib/any_cache/adapters/active_support_redis_cache_store.rb +129 -0
- data/lib/any_cache/adapters/basic.rb +118 -0
- data/lib/any_cache/adapters/dalli.rb +140 -0
- data/lib/any_cache/adapters/delegator.rb +36 -0
- data/lib/any_cache/adapters/redis.rb +151 -0
- data/lib/any_cache/adapters/redis_store.rb +41 -0
- data/lib/any_cache/error.rb +11 -0
- data/lib/any_cache/version.rb +5 -2
- metadata +127 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b5cb4e91050841afb6fb75ae7cdf793a209291e28521a07467c3172ca6327b7
|
4
|
+
data.tar.gz: 127050e1c3e23797c9ea49c418818ecb54dc34c2c882cf3a20ea095bfe5a852b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dac1643ccf2b3ade6a75c5c7f55c37b69bd41ac8b057c43cb581a58bd2eb3f82e0e5d66562a66f8545a4ec1289f004f5bb3bc589861f6b9c980b297dc41bc58c
|
7
|
+
data.tar.gz: 83ec5094b541f79268691ea95e8daeaa01a6d296fbe7e1728289cf7e96ba03536787a3af137350a88194f7264067ffb2a6457611a22bccdf3ef26731e7a46c44
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
inherit_gem:
|
2
|
+
armitage-rubocop:
|
3
|
+
- lib/rubocop.general.yml
|
4
|
+
- lib/rubocop.rspec.yml
|
5
|
+
|
6
|
+
AllCops:
|
7
|
+
UseCache: true
|
8
|
+
TargetRubyVersion: 2.5.1
|
9
|
+
Include:
|
10
|
+
- bin/console
|
11
|
+
- lib/**/*.rb
|
12
|
+
- spec/**/*.rb
|
13
|
+
- Gemfile
|
14
|
+
- Rakefile
|
15
|
+
- any_cache.gemspec
|
16
|
+
|
17
|
+
Layout/MultilineOperationIndentation:
|
18
|
+
Enabled: false
|
data/.travis.yml
CHANGED
@@ -1,5 +1,84 @@
|
|
1
|
-
sudo: false
|
2
1
|
language: ruby
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
sudo: false
|
3
|
+
before_install: gem install bundler
|
4
|
+
cache: bundler
|
5
|
+
script:
|
6
|
+
- bundle exec rspec
|
7
|
+
services:
|
8
|
+
- redis-server
|
9
|
+
- memcached
|
10
|
+
matrix:
|
11
|
+
fast_finish: true
|
12
|
+
include:
|
13
|
+
- rvm: 2.3.7
|
14
|
+
gemfile: gemfiles/active_support.gemfile
|
15
|
+
env: TEST_AS_MEMORY_STORE_CACHE=true
|
16
|
+
- rvm: 2.4.4
|
17
|
+
gemfile: gemfiles/active_support.gemfile
|
18
|
+
env: TEST_AS_MEMORY_STORE_CACHE=true
|
19
|
+
- rvm: 2.5.1
|
20
|
+
gemfile: gemfiles/active_support.gemfile
|
21
|
+
env: TEST_AS_MEMORY_STORE_CACHE=true
|
22
|
+
- rvm: ruby-head
|
23
|
+
gemfile: gemfiles/active_support.gemfile
|
24
|
+
env: TEST_AS_MEMORY_STORE_CACHE=true
|
25
|
+
- rvm: 2.3.7
|
26
|
+
gemfile: gemfiles/active_support.gemfile
|
27
|
+
env: TEST_AS_FILE_STORE_CACHE=true
|
28
|
+
- rvm: 2.4.4
|
29
|
+
gemfile: gemfiles/active_support.gemfile
|
30
|
+
env: TEST_AS_FILE_STORE_CACHE=true
|
31
|
+
- rvm: 2.5.1
|
32
|
+
gemfile: gemfiles/active_support.gemfile
|
33
|
+
env: TEST_AS_FILE_STORE_CACHE=true
|
34
|
+
- rvm: ruby-head
|
35
|
+
gemfile: gemfiles/active_support.gemfile
|
36
|
+
env: TEST_AS_FILE_STORE_CACHE=true
|
37
|
+
- rvm: 2.3.7
|
38
|
+
gemfile: gemfiles/active_support_with_redis.gemfile
|
39
|
+
env: TEST_AS_REDIS_CACHE_STORE_CACHE=true
|
40
|
+
- rvm: 2.4.4
|
41
|
+
gemfile: gemfiles/active_support_with_redis.gemfile
|
42
|
+
env: TEST_AS_REDIS_CACHE_STORE_CACHE=true
|
43
|
+
- rvm: 2.5.1
|
44
|
+
gemfile: gemfiles/active_support_with_redis.gemfile
|
45
|
+
env: TEST_AS_REDIS_CACHE_STORE_CACHE=true
|
46
|
+
- rvm: ruby-head
|
47
|
+
gemfile: gemfiles/active_support_with_redis.gemfile
|
48
|
+
env: TEST_AS_REDIS_CACHE_STORE_CACHE=true
|
49
|
+
- rvm: 2.3.7
|
50
|
+
gemfile: gemfiles/dalli.gemfile
|
51
|
+
env: TEST_DALLI_CACHE=true
|
52
|
+
- rvm: 2.4.4
|
53
|
+
gemfile: gemfiles/dalli.gemfile
|
54
|
+
env: TEST_DALLI_CACHE=true
|
55
|
+
- rvm: 2.5.1
|
56
|
+
gemfile: gemfiles/dalli.gemfile
|
57
|
+
env: TEST_DALLI_CACHE=true
|
58
|
+
- rvm: ruby-head
|
59
|
+
gemfile: gemfiles/dalli.gemfile
|
60
|
+
env: TEST_DALLI_CACHE=true
|
61
|
+
- rvm: 2.3.7
|
62
|
+
gemfile: gemfiles/redis_store.gemfile
|
63
|
+
env: TEST_REDIS_STORE_CACHE=true
|
64
|
+
- rvm: 2.4.4
|
65
|
+
gemfile: gemfiles/redis_store.gemfile
|
66
|
+
env: TEST_REDIS_STORE_CACHE=true
|
67
|
+
- rvm: 2.5.1
|
68
|
+
gemfile: gemfiles/redis_store.gemfile
|
69
|
+
env: TEST_REDIS_STORE_CACHE=true
|
70
|
+
- rvm: ruby-head
|
71
|
+
gemfile: gemfiles/redis_store.gemfile
|
72
|
+
env: TEST_REDIS_STORE_CACHE=true
|
73
|
+
- rvm: 2.3.7
|
74
|
+
gemfile: gemfiles/redis_store.gemfile
|
75
|
+
env: TEST_REDIS_CACHE=true
|
76
|
+
- rvm: 2.4.4
|
77
|
+
gemfile: gemfiles/redis_store.gemfile
|
78
|
+
env: TEST_REDIS_CACHE=true
|
79
|
+
- rvm: 2.5.1
|
80
|
+
gemfile: gemfiles/redis_store.gemfile
|
81
|
+
env: TEST_REDIS_CACHE=true
|
82
|
+
- rvm: ruby-head
|
83
|
+
gemfile: gemfiles/redis_store.gemfile
|
84
|
+
env: TEST_REDIS_CACHE=true
|
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
6
|
|
5
7
|
# Specify your gem's dependencies in any_cache.gemspec
|
6
8
|
gemspec
|
data/README.md
CHANGED
@@ -1,43 +1,266 @@
|
|
1
|
-
# AnyCache
|
1
|
+
# AnyCache · [![Gem Version](https://badge.fury.io/rb/any_cache.svg)](https://badge.fury.io/rb/any_cache) [![Build Status](https://travis-ci.org/0exp/any_cache.svg?branch=master)](https://travis-ci.org/0exp/any_cache) [![Coverage Status](https://coveralls.io/repos/github/0exp/any_cache/badge.svg)](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
5
|
|
5
|
-
|
6
|
+
Supported clients:
|
6
7
|
|
7
|
-
|
8
|
+
- `Redis` ([gem redis](https://github.com/redis/redis-rb)) ([redis storage](https://redis.io/))
|
9
|
+
- `Redis::Store` ([gem redis-store](https://github.com/redis-store/redis-store)) ([redis storage](https://redis.io/))
|
10
|
+
- `Dalli::Client` ([gem dalli](https://github.com/petergoldstein/dalli)) ([memcached storage](https://memcached.org/))
|
11
|
+
- `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
|
+
- `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
|
+
---
|
8
16
|
|
9
|
-
|
17
|
+
## Installation
|
10
18
|
|
11
19
|
```ruby
|
12
20
|
gem 'any_cache'
|
13
21
|
```
|
14
22
|
|
15
|
-
|
23
|
+
```shell
|
24
|
+
bundle install
|
25
|
+
# --- or ---
|
26
|
+
gem install any_cache
|
27
|
+
```
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'any_cache'
|
31
|
+
```
|
32
|
+
|
33
|
+
---
|
34
|
+
|
35
|
+
## Usage / Table of Contents
|
36
|
+
|
37
|
+
- [Creation](#creation)
|
38
|
+
- **Operations**
|
39
|
+
- [Read](#read)
|
40
|
+
- [Write](#write)
|
41
|
+
- [Delete](#delete)
|
42
|
+
- [Increment](#increment)
|
43
|
+
- [Decrement](#decrement)
|
44
|
+
- [Expire](#expire)
|
45
|
+
- [Persist](#persist)
|
46
|
+
- [Clear](#clear)
|
47
|
+
|
48
|
+
---
|
49
|
+
|
50
|
+
### Creation
|
51
|
+
|
52
|
+
To instantiate AnyCache instance you have to provide a client.
|
53
|
+
Client - an independent driver that works with a corresponding cache storage (external dependency).
|
54
|
+
Supported clients:
|
55
|
+
|
56
|
+
- `Redis`
|
57
|
+
- `Redis::Store`
|
58
|
+
- `Dalli::Client`
|
59
|
+
- `ActiveSupport::Cache::RedisCacheStore`
|
60
|
+
- `ActiveSupport::Cache::FileStore`
|
61
|
+
- `ActiveSupport::Cache::MemoryStore`
|
62
|
+
|
63
|
+
`AnyCache` instantiation:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
# 1) create client object
|
67
|
+
client = Redis.new(...)
|
68
|
+
# -- or --
|
69
|
+
client = Redis::Store.new(...)
|
70
|
+
# -- or --
|
71
|
+
client = Dalli::Client.new(...)
|
72
|
+
# -- or --
|
73
|
+
client = ActiveSupport::Cache::RedisCacheStore.new(...)
|
74
|
+
# -- or --
|
75
|
+
client = ActiveSupport::Cache::FileStore.new(...)
|
76
|
+
# -- or --
|
77
|
+
client = ActiveSupport::Cache::MemoryStore.new(...)
|
78
|
+
|
79
|
+
# 2) build AnyCache instance
|
80
|
+
any_cache = AnyCache.build(client) # => <AnyCache:0x00007f990527f268 ...>
|
81
|
+
```
|
82
|
+
|
83
|
+
If you want to use your own cache client implementation, you should provide an object that responds to:
|
84
|
+
|
85
|
+
- `#read(key, [**options])` ([doc](#read))
|
86
|
+
- `#write(key, value, [**options])` ([doc](#write))
|
87
|
+
- `#delete(key, [**options])` ([doc](#delete))
|
88
|
+
- `#increment(key, amount, [**options])` ([doc](#increment))
|
89
|
+
- `#decrmeent(key, amount, [**options])` ([doc](#decrement))
|
90
|
+
- `#expire(key, [**options])` ([doc](#expire))
|
91
|
+
- `#persist(key, [**options])` ([doc](#persist))
|
92
|
+
- `#clear([**options])` ([doc](#clear))
|
93
|
+
|
94
|
+
---
|
16
95
|
|
17
|
-
|
96
|
+
### Read
|
18
97
|
|
19
|
-
|
98
|
+
- `AnyCache#read(key)` - get entry value from cache storage
|
20
99
|
|
21
|
-
|
100
|
+
```ruby
|
101
|
+
# --- entry exists ---
|
102
|
+
any_cache.read("data") # => "some_data"
|
103
|
+
|
104
|
+
# --- entry doesnt exist ---
|
105
|
+
any_cache.read("data") # => nil
|
106
|
+
```
|
107
|
+
|
108
|
+
---
|
109
|
+
|
110
|
+
### Write
|
111
|
+
|
112
|
+
- `AnyCache#write(key, value, [expires_in:])` - write new entry to cache storage
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
# --- permanent entry ---
|
116
|
+
any_cache.write("data", 123)
|
117
|
+
|
118
|
+
# --- temporal entry (expires in 60 seconds) ---
|
119
|
+
any_cache.write("data", 123, expires_in: 60)
|
120
|
+
```
|
121
|
+
|
122
|
+
---
|
123
|
+
|
124
|
+
### Delete
|
125
|
+
|
126
|
+
- `AnyCache#delete(key)` - remove entry from cache storage
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
any_cache.delete("data")
|
130
|
+
```
|
131
|
+
|
132
|
+
---
|
133
|
+
|
134
|
+
### Increment
|
135
|
+
|
136
|
+
- `AnyCache#increment(key, amount = 1, [expires_in:])` - increment entry's value by passed amount
|
137
|
+
and set new expiration time if needed
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
# --- increment existing entry ---
|
141
|
+
any_cache.write("data", 1)
|
22
142
|
|
23
|
-
|
143
|
+
# --- increment by default value (1) ---
|
144
|
+
any_cache.increment("data") # => 2
|
145
|
+
|
146
|
+
# --- increment by custom value ---
|
147
|
+
any_cache.increment("data", 12) # => 14
|
148
|
+
|
149
|
+
# --- increment and expire after 31 seconds
|
150
|
+
any_cache.incrmeent("data", expires_in: 31) # => 15
|
151
|
+
|
152
|
+
# --- increment nonexistent entry (create new entry) ---
|
153
|
+
any_cache.increment("another_data", 5, expires_in: 5) # => 5
|
154
|
+
```
|
155
|
+
|
156
|
+
---
|
157
|
+
|
158
|
+
### Decrement
|
159
|
+
|
160
|
+
- `AnyCache#decrement(key, amount = 1, [expires_in:])` - decrement entry's value by passed amount
|
161
|
+
and set new expiration time if needed
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
# --- decrement existing entry ---
|
165
|
+
any_cache.write("data", 15)
|
166
|
+
|
167
|
+
# --- decrement by default value (1) ---
|
168
|
+
any_cache.decrement("data") # => 14
|
169
|
+
|
170
|
+
# --- decrement by custom value ---
|
171
|
+
any_cache.decrement("data", 10) # => 4
|
172
|
+
|
173
|
+
# --- decrement and expire after 5 seconds
|
174
|
+
any_cache.decrememnt("data", expirs_in: 5) # => 3
|
175
|
+
|
176
|
+
# --- decrement nonexistent entry (create new entry) ---
|
177
|
+
any_cache.decrememnt("another_data", 2, expires_in: 10) # => -2 (or 0 for Dalli::Client)
|
178
|
+
```
|
179
|
+
|
180
|
+
---
|
181
|
+
|
182
|
+
### Expire
|
183
|
+
|
184
|
+
- `AnyCache#expire(key, [expires_in:])` - expire entry immediately or set the new expiration time
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
# --- expire immediately ---
|
188
|
+
any_cache.expire("data")
|
189
|
+
|
190
|
+
# --- set new expiration time (in seconds) --
|
191
|
+
any_cache.expire("data", expires_in: 36)
|
192
|
+
```
|
193
|
+
|
194
|
+
---
|
195
|
+
|
196
|
+
### Persist
|
197
|
+
|
198
|
+
- `AnyCache#persist(key)` - change entry's expiration time to permanent
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
# --- create temporal entry (30 seconds) ---
|
202
|
+
any_cache.write("data", { a: 1 }, expires_in: 30)
|
203
|
+
|
204
|
+
# --- remove entry expiration (make it permanent) ---
|
205
|
+
any_cache.persist("data")
|
206
|
+
```
|
207
|
+
|
208
|
+
---
|
209
|
+
|
210
|
+
### Clear
|
211
|
+
|
212
|
+
- `AnyCache#clear()` - clear cache database
|
213
|
+
|
214
|
+
```ruby
|
215
|
+
# --- prepare cache data ---
|
216
|
+
any_cache.write("data", { a: 1, b: 2 })
|
217
|
+
any_cache.write("another_data", 123_456)
|
218
|
+
|
219
|
+
any_cache.read("data") # => { a: 1, b: 2 }
|
220
|
+
any_cache.read("another_data") # => 123_456
|
221
|
+
|
222
|
+
# --- clear cache ---
|
223
|
+
any_cache.clear
|
224
|
+
|
225
|
+
any_cache.read("data") # => nil
|
226
|
+
any_cache.read("another_data") # => nil
|
227
|
+
```
|
228
|
+
|
229
|
+
---
|
230
|
+
|
231
|
+
## Build
|
232
|
+
|
233
|
+
- see [bin/rspec](bin/rspec)
|
234
|
+
|
235
|
+
```shell
|
236
|
+
bin/rspec --test-redis # run specs with Redis
|
237
|
+
bin/rspec --test-redis-store # run specs with Redis::Store
|
238
|
+
bin/rspec --test-dalli # run specs with Dalli::Client
|
239
|
+
bin/rspec --test-as-file-store # run specs with ActiveSupport::Cache::FileStore
|
240
|
+
bin/rspec --test-as-memory-store # run specs with ActiveSupport::Cache::MemoryStore
|
241
|
+
bin/rspec --test-as-redis-cache-store # run specs with ActiveSupport::Cache::RedisCacheStore
|
242
|
+
```
|
24
243
|
|
25
|
-
|
244
|
+
---
|
26
245
|
|
27
|
-
##
|
246
|
+
## Roadmap
|
28
247
|
|
29
|
-
|
248
|
+
- configuration layer with ability to instantiate cache clients implicitly
|
30
249
|
|
31
|
-
|
250
|
+
---
|
32
251
|
|
33
252
|
## Contributing
|
34
253
|
|
35
|
-
|
254
|
+
- Fork it (https://github.com/0exp/any_cache/fork)
|
255
|
+
- Create your feature branch (`git checkout -b feature/my-new-feature`)
|
256
|
+
- Commit your changes (`git commit -am 'Add some feature'`)
|
257
|
+
- Push to the branch (`git push origin feature/my-new-feature`)
|
258
|
+
- Create new Pull Request
|
36
259
|
|
37
260
|
## License
|
38
261
|
|
39
|
-
|
262
|
+
Released under MIT License.
|
40
263
|
|
41
|
-
##
|
264
|
+
## Authors
|
42
265
|
|
43
|
-
|
266
|
+
Created by [Rustam Ibragimov](https://github.com/0exp/)
|