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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -2
  3. data/.rspec +1 -1
  4. data/.rubocop.yml +18 -0
  5. data/.travis.yml +83 -4
  6. data/CHANGELOG.md +5 -0
  7. data/Gemfile +4 -2
  8. data/README.md +241 -18
  9. data/Rakefile +6 -4
  10. data/any_cache.gemspec +21 -7
  11. data/bin/console +5 -11
  12. data/bin/rspec +119 -0
  13. data/gemfiles/active_support.gemfile +7 -0
  14. data/gemfiles/active_support_with_redis.gemfile +8 -0
  15. data/gemfiles/dalli.gemfile +7 -0
  16. data/gemfiles/redis.gemfile +7 -0
  17. data/gemfiles/redis_store.gemfile +7 -0
  18. data/lib/any_cache.rb +49 -3
  19. data/lib/any_cache/adapters.rb +40 -0
  20. data/lib/any_cache/adapters/active_support_file_store.rb +26 -0
  21. data/lib/any_cache/adapters/active_support_file_store/decrement.rb +10 -0
  22. data/lib/any_cache/adapters/active_support_file_store/expire.rb +10 -0
  23. data/lib/any_cache/adapters/active_support_file_store/fetching.rb +28 -0
  24. data/lib/any_cache/adapters/active_support_file_store/increment.rb +10 -0
  25. data/lib/any_cache/adapters/active_support_file_store/operation.rb +10 -0
  26. data/lib/any_cache/adapters/active_support_file_store/persist.rb +10 -0
  27. data/lib/any_cache/adapters/active_support_memory_store.rb +26 -0
  28. data/lib/any_cache/adapters/active_support_memory_store/decrement.rb +10 -0
  29. data/lib/any_cache/adapters/active_support_memory_store/expire.rb +10 -0
  30. data/lib/any_cache/adapters/active_support_memory_store/fetching.rb +16 -0
  31. data/lib/any_cache/adapters/active_support_memory_store/increment.rb +10 -0
  32. data/lib/any_cache/adapters/active_support_memory_store/operation.rb +10 -0
  33. data/lib/any_cache/adapters/active_support_memory_store/persist.rb +10 -0
  34. data/lib/any_cache/adapters/active_support_naive_store.rb +150 -0
  35. data/lib/any_cache/adapters/active_support_naive_store/decrement.rb +72 -0
  36. data/lib/any_cache/adapters/active_support_naive_store/expire.rb +25 -0
  37. data/lib/any_cache/adapters/active_support_naive_store/increment.rb +71 -0
  38. data/lib/any_cache/adapters/active_support_naive_store/operation.rb +64 -0
  39. data/lib/any_cache/adapters/active_support_naive_store/persist.rb +22 -0
  40. data/lib/any_cache/adapters/active_support_redis_cache_store.rb +129 -0
  41. data/lib/any_cache/adapters/basic.rb +118 -0
  42. data/lib/any_cache/adapters/dalli.rb +140 -0
  43. data/lib/any_cache/adapters/delegator.rb +36 -0
  44. data/lib/any_cache/adapters/redis.rb +151 -0
  45. data/lib/any_cache/adapters/redis_store.rb +41 -0
  46. data/lib/any_cache/error.rb +11 -0
  47. data/lib/any_cache/version.rb +5 -2
  48. metadata +127 -5
@@ -0,0 +1,151 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AnyCache::Adapters
4
+ # @api private
5
+ # @since 0.1.0
6
+ class Redis < Basic
7
+ class << self
8
+ # @param driver [Object]
9
+ # @return [Boolean]
10
+ #
11
+ # @api private
12
+ # @since 0.1.0
13
+ def supported_driver?(driver)
14
+ defined?(::Redis) && driver.is_a?(::Redis)
15
+ end
16
+ end
17
+
18
+ # @return [NilClass]
19
+ #
20
+ # @api private
21
+ # @since 0.1.0
22
+ NO_EXPIRATION_TTL = nil
23
+
24
+ # @return [Integer]
25
+ #
26
+ # @api private
27
+ # @since 0.1.0
28
+ DEAD_TTL = 0
29
+
30
+ # @return [Integer]
31
+ #
32
+ # @api private
33
+ # @since 0.1.0
34
+ DEFAULT_INCR_DECR_AMOUNT = 1
35
+
36
+ # @since 0.1.0
37
+ def_delegators :driver,
38
+ :get,
39
+ :set,
40
+ :setex,
41
+ :del,
42
+ :incrby,
43
+ :decrby,
44
+ :pipelined,
45
+ :flushdb
46
+
47
+ # @param key [String]
48
+ # @param options [Hash]
49
+ # @return [Object]
50
+ #
51
+ # @api private
52
+ # @since 0.1.0
53
+ def read(key, **options)
54
+ get(key)
55
+ end
56
+
57
+ # @param key [String]
58
+ # @param value [Object]
59
+ # @option expires_in [NilClass, Integer] Time in seconds
60
+ # @return [void]
61
+ #
62
+ # @api private
63
+ # @since 0.1.0
64
+ def write(key, value, **options)
65
+ expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
66
+
67
+ expires_in ? setex(key, expires_in, value) : set(key, value)
68
+ end
69
+
70
+ # @param key [String]
71
+ # @param options [Hash]
72
+ # @return [void]
73
+ #
74
+ # @api private
75
+ # @since 0.1.0
76
+ def delete(key, **options)
77
+ del(key)
78
+ end
79
+
80
+ # @param key [String]
81
+ # @param amount [Integer]
82
+ # @option expires_in [NilClass, Integer] Time in seconds
83
+ # @return [NilClass, Integer]
84
+ #
85
+ # @api private
86
+ # @since 0.1.0
87
+ def increment(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options)
88
+ expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
89
+ new_amount = nil
90
+
91
+ # TODO: think about Redis#multi
92
+ pipelined do
93
+ new_amount = incrby(key, amount)
94
+ expire(key, expires_in: expires_in) if expires_in
95
+ end
96
+
97
+ new_amount&.value
98
+ end
99
+
100
+ # @param key [String]
101
+ # @param amount [Integer]
102
+ # @options expires_in [NillClass, Integer] Time in seconds
103
+ # @return [NillClass, Integer]
104
+ #
105
+ # @api private
106
+ # @since 0.1.0
107
+ def decrement(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options)
108
+ expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
109
+ new_amount = nil
110
+
111
+ # TODO: think about Redis#multi
112
+ pipelined do
113
+ new_amount = decrby(key, amount)
114
+ expire(key, expires_in: expires_in) if expires_in
115
+ end
116
+
117
+ new_amount&.value
118
+ end
119
+
120
+ # @param key [String]
121
+ # @option expires_in [Integer]
122
+ # @return [void]
123
+ #
124
+ # @api private
125
+ # @since 0.1.0
126
+ def expire(key, expires_in: DEAD_TTL)
127
+ expires_in ||= DEAD_TTL unless expires_in
128
+
129
+ driver.expire(key, expires_in)
130
+ end
131
+
132
+ # @param key [String]
133
+ # @param options [Hash]
134
+ # @return [void]
135
+ #
136
+ # @api private
137
+ # @since 0.1.0
138
+ def persist(key, **options)
139
+ driver.persist(key)
140
+ end
141
+
142
+ # @param options [Hash]
143
+ # @return [void]
144
+ #
145
+ # @api private
146
+ # @since 0.1.0
147
+ def clear(**options)
148
+ flushdb
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AnyCache::Adapters
4
+ # @api private
5
+ # @since 0.1.0
6
+ class RedisStore < Redis
7
+ class << self
8
+ # @param driver [Object]
9
+ # @return [Boolean]
10
+ #
11
+ # @api private
12
+ # @since 0.1.0
13
+ def supported_driver?(driver)
14
+ defined?(::Redis::Store) && driver.is_a?(::Redis::Store)
15
+ end
16
+ end
17
+
18
+ # @param key [String]
19
+ # @param options [Hash]
20
+ # @return [Object]
21
+ #
22
+ # @api private
23
+ # @since 0.1.0
24
+ def read(key, **options)
25
+ get(key, raw: true)
26
+ end
27
+
28
+ # @param key [String]
29
+ # @param value [Object]
30
+ # @option expires_in [NilClass, Integer] Time in seconds
31
+ # @return [void]
32
+ #
33
+ # @api private
34
+ # @since 0.1.0
35
+ def write(key, value, **options)
36
+ expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
37
+
38
+ expires_in ? setex(key, expires_in, value, raw: true) : set(key, value, raw: true)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.1.0
5
+ class AnyCache
6
+ # @since 0.1.0
7
+ Error = Class.new(StandardError)
8
+
9
+ # @since 0.1.0
10
+ UnsupportedDriverError = Class.new(Error)
11
+ end
@@ -1,3 +1,6 @@
1
- module AnyCache
2
- VERSION = "0.0.0"
1
+ # frozen_string_literal: true
2
+
3
+ class AnyCache
4
+ # @since 0.1.0
5
+ VERSION = '0.1.0'
3
6
  end
metadata CHANGED
@@ -1,15 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: any_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Ibragimov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-19 00:00:00.000000000 Z
11
+ date: 2018-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: concurrent-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: armitage-rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: qonfig
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.6'
13
97
  - !ruby/object:Gem::Dependency
14
98
  name: bundler
15
99
  requirement: !ruby/object:Gem::Requirement
@@ -52,7 +136,9 @@ dependencies:
52
136
  - - ">="
53
137
  - !ruby/object:Gem::Version
54
138
  version: '0'
55
- description: Soon
139
+ description: AnyCache - a simplest cache wrapper that provides a minimalistic generic
140
+ interface for the all well-known cache storages and includes a minimal set of necessary
141
+ operations.
56
142
  email:
57
143
  - iamdaiver@icloud.com
58
144
  executables: []
@@ -61,7 +147,9 @@ extra_rdoc_files: []
61
147
  files:
62
148
  - ".gitignore"
63
149
  - ".rspec"
150
+ - ".rubocop.yml"
64
151
  - ".travis.yml"
152
+ - CHANGELOG.md
65
153
  - CODE_OF_CONDUCT.md
66
154
  - Gemfile
67
155
  - LICENSE.txt
@@ -69,8 +157,42 @@ files:
69
157
  - Rakefile
70
158
  - any_cache.gemspec
71
159
  - bin/console
160
+ - bin/rspec
72
161
  - bin/setup
162
+ - gemfiles/active_support.gemfile
163
+ - gemfiles/active_support_with_redis.gemfile
164
+ - gemfiles/dalli.gemfile
165
+ - gemfiles/redis.gemfile
166
+ - gemfiles/redis_store.gemfile
73
167
  - lib/any_cache.rb
168
+ - lib/any_cache/adapters.rb
169
+ - lib/any_cache/adapters/active_support_file_store.rb
170
+ - lib/any_cache/adapters/active_support_file_store/decrement.rb
171
+ - lib/any_cache/adapters/active_support_file_store/expire.rb
172
+ - lib/any_cache/adapters/active_support_file_store/fetching.rb
173
+ - lib/any_cache/adapters/active_support_file_store/increment.rb
174
+ - lib/any_cache/adapters/active_support_file_store/operation.rb
175
+ - lib/any_cache/adapters/active_support_file_store/persist.rb
176
+ - lib/any_cache/adapters/active_support_memory_store.rb
177
+ - lib/any_cache/adapters/active_support_memory_store/decrement.rb
178
+ - lib/any_cache/adapters/active_support_memory_store/expire.rb
179
+ - lib/any_cache/adapters/active_support_memory_store/fetching.rb
180
+ - lib/any_cache/adapters/active_support_memory_store/increment.rb
181
+ - lib/any_cache/adapters/active_support_memory_store/operation.rb
182
+ - lib/any_cache/adapters/active_support_memory_store/persist.rb
183
+ - lib/any_cache/adapters/active_support_naive_store.rb
184
+ - lib/any_cache/adapters/active_support_naive_store/decrement.rb
185
+ - lib/any_cache/adapters/active_support_naive_store/expire.rb
186
+ - lib/any_cache/adapters/active_support_naive_store/increment.rb
187
+ - lib/any_cache/adapters/active_support_naive_store/operation.rb
188
+ - lib/any_cache/adapters/active_support_naive_store/persist.rb
189
+ - lib/any_cache/adapters/active_support_redis_cache_store.rb
190
+ - lib/any_cache/adapters/basic.rb
191
+ - lib/any_cache/adapters/dalli.rb
192
+ - lib/any_cache/adapters/delegator.rb
193
+ - lib/any_cache/adapters/redis.rb
194
+ - lib/any_cache/adapters/redis_store.rb
195
+ - lib/any_cache/error.rb
74
196
  - lib/any_cache/version.rb
75
197
  homepage: https://github.com/0exp/any_cache
76
198
  licenses:
@@ -84,7 +206,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
206
  requirements:
85
207
  - - ">="
86
208
  - !ruby/object:Gem::Version
87
- version: '0'
209
+ version: 2.3.7
88
210
  required_rubygems_version: !ruby/object:Gem::Requirement
89
211
  requirements:
90
212
  - - ">="
@@ -95,5 +217,5 @@ rubyforge_project:
95
217
  rubygems_version: 2.7.6
96
218
  signing_key:
97
219
  specification_version: 4
98
- summary: Soon
220
+ summary: AnyCache - a simplest cache wrapper
99
221
  test_files: []