any_cache 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @api private
|
4
|
+
# @since 0.2.0
|
5
|
+
module AnyCache::Drivers::RedisStore
|
6
|
+
class << self
|
7
|
+
# @param driver [::Redis::Store]
|
8
|
+
# @return [Boolean]
|
9
|
+
#
|
10
|
+
# @api private
|
11
|
+
# @since 0.2.0
|
12
|
+
def supported_source?(driver)
|
13
|
+
defined?(::Redis::Store) && driver.is_a?(::Redis::Store)
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param settings [Qonfig::Settings]
|
17
|
+
# @return [::Redis::Store]
|
18
|
+
#
|
19
|
+
# @api private
|
20
|
+
# @sicne 0.2.0
|
21
|
+
def build(settings)
|
22
|
+
::Redis::Store.new(settings.options)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @api private
|
4
|
+
# @since 0.2.0
|
5
|
+
module AnyCache::Drivers
|
6
|
+
require_relative 'drivers/dalli'
|
7
|
+
require_relative 'drivers/redis'
|
8
|
+
require_relative 'drivers/redis_store'
|
9
|
+
require_relative 'drivers/active_support_file_store'
|
10
|
+
require_relative 'drivers/active_support_memory_store'
|
11
|
+
require_relative 'drivers/active_support_redis_cache_store'
|
12
|
+
require_relative 'drivers/active_support_mem_cache_store'
|
13
|
+
|
14
|
+
class << self
|
15
|
+
# @param config [Qonfig::DataSet]
|
16
|
+
# @return [Object]
|
17
|
+
#
|
18
|
+
# @raise [AnyCache::UnsupportedDriverError]
|
19
|
+
#
|
20
|
+
# @api private
|
21
|
+
# @since 0.2.0
|
22
|
+
def build(config)
|
23
|
+
driver = config[:driver]
|
24
|
+
|
25
|
+
case driver
|
26
|
+
when :redis
|
27
|
+
Redis.build(config[:redis])
|
28
|
+
when :redis_store
|
29
|
+
RedisStore.build(config[:redis_store])
|
30
|
+
when :dalli
|
31
|
+
Dalli.build(config[:dalli])
|
32
|
+
when :as_file_store
|
33
|
+
ActiveSupportFileStore.build(config[:as_file_store])
|
34
|
+
when :as_memory_store
|
35
|
+
ActiveSupportMemoryStore.build(config[:as_memory_store])
|
36
|
+
when :as_redis_cache_store
|
37
|
+
ActiveSupportRedisCacheStore.build(config[:as_redis_cache_store])
|
38
|
+
when :as_mem_cache_store
|
39
|
+
ActiveSupportMemCacheStore.build(config[:as_mem_cache_store])
|
40
|
+
else
|
41
|
+
raise AnyCache::UnsupportedDriverError
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/any_cache/version.rb
CHANGED
data/lib/any_cache.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'qonfig'
|
3
4
|
require 'securerandom'
|
4
5
|
require 'concurrent/atomic/reentrant_read_write_lock'
|
5
6
|
|
@@ -7,22 +8,64 @@ require 'concurrent/atomic/reentrant_read_write_lock'
|
|
7
8
|
# @since 0.1.0
|
8
9
|
class AnyCache
|
9
10
|
require_relative 'any_cache/version'
|
11
|
+
require_relative 'any_cache/error'
|
12
|
+
require_relative 'any_cache/drivers'
|
10
13
|
require_relative 'any_cache/adapters'
|
11
14
|
|
12
15
|
# @since 0.1.0
|
13
16
|
extend Forwardable
|
14
17
|
|
18
|
+
# @since 0.2.0
|
19
|
+
include Qonfig::Configurable
|
20
|
+
|
21
|
+
# @since 0.2.0
|
22
|
+
configuration do
|
23
|
+
setting :driver
|
24
|
+
|
25
|
+
setting :redis do
|
26
|
+
setting :options, {}
|
27
|
+
end
|
28
|
+
|
29
|
+
setting :redis_store do
|
30
|
+
setting :options, {}
|
31
|
+
end
|
32
|
+
|
33
|
+
setting :dalli do
|
34
|
+
setting :servers, nil
|
35
|
+
setting :options, {}
|
36
|
+
end
|
37
|
+
|
38
|
+
setting :as_file_store do
|
39
|
+
setting :cache_path
|
40
|
+
setting :options, {}
|
41
|
+
end
|
42
|
+
|
43
|
+
setting :as_memory_store do
|
44
|
+
setting :options, {}
|
45
|
+
end
|
46
|
+
|
47
|
+
setting :as_redis_cache_store do
|
48
|
+
setting :options, {}
|
49
|
+
end
|
50
|
+
|
51
|
+
setting :as_mem_cache_store do
|
52
|
+
setting :servers, nil
|
53
|
+
setting :options, {}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
15
57
|
class << self
|
16
58
|
# @param driver [Object]
|
17
59
|
# @return [AnyCache]
|
18
60
|
#
|
19
|
-
# @api
|
61
|
+
# @api public
|
20
62
|
# @since 0.1.0
|
21
|
-
def build(driver)
|
63
|
+
def build(driver = Drivers.build(config))
|
22
64
|
new(Adapters.build(driver))
|
23
65
|
end
|
24
66
|
end
|
25
67
|
|
68
|
+
# @api public
|
26
69
|
# @since 0.1.0
|
27
70
|
def_delegators :adapter,
|
28
71
|
:read,
|
@@ -32,7 +75,9 @@ class AnyCache
|
|
32
75
|
:decrement,
|
33
76
|
:expire,
|
34
77
|
:persist,
|
35
|
-
:clear
|
78
|
+
:clear,
|
79
|
+
:exist?,
|
80
|
+
:fetch
|
36
81
|
|
37
82
|
# @return [AnyCache::Adapters::Basic]
|
38
83
|
#
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: any_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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-
|
11
|
+
date: 2018-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -25,75 +25,75 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: qonfig
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
34
|
-
type: :
|
33
|
+
version: '0.6'
|
34
|
+
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
40
|
+
version: '0.6'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: coveralls
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
47
|
+
version: '0.8'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0.
|
54
|
+
version: '0.8'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: simplecov
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0.
|
61
|
+
version: '0.16'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0.
|
68
|
+
version: '0.16'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: armitage-rubocop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0.7'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0.7'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '3.8'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '3.8'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: bundler
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- bin/rspec
|
161
161
|
- bin/setup
|
162
162
|
- gemfiles/active_support.gemfile
|
163
|
+
- gemfiles/active_support_with_dalli.gemfile
|
163
164
|
- gemfiles/active_support_with_redis.gemfile
|
164
165
|
- gemfiles/dalli.gemfile
|
165
166
|
- gemfiles/redis.gemfile
|
@@ -173,6 +174,7 @@ files:
|
|
173
174
|
- lib/any_cache/adapters/active_support_file_store/increment.rb
|
174
175
|
- lib/any_cache/adapters/active_support_file_store/operation.rb
|
175
176
|
- lib/any_cache/adapters/active_support_file_store/persist.rb
|
177
|
+
- lib/any_cache/adapters/active_support_mem_cache_store.rb
|
176
178
|
- lib/any_cache/adapters/active_support_memory_store.rb
|
177
179
|
- lib/any_cache/adapters/active_support_memory_store/decrement.rb
|
178
180
|
- lib/any_cache/adapters/active_support_memory_store/expire.rb
|
@@ -192,6 +194,14 @@ files:
|
|
192
194
|
- lib/any_cache/adapters/delegator.rb
|
193
195
|
- lib/any_cache/adapters/redis.rb
|
194
196
|
- lib/any_cache/adapters/redis_store.rb
|
197
|
+
- lib/any_cache/drivers.rb
|
198
|
+
- lib/any_cache/drivers/active_support_file_store.rb
|
199
|
+
- lib/any_cache/drivers/active_support_mem_cache_store.rb
|
200
|
+
- lib/any_cache/drivers/active_support_memory_store.rb
|
201
|
+
- lib/any_cache/drivers/active_support_redis_cache_store.rb
|
202
|
+
- lib/any_cache/drivers/dalli.rb
|
203
|
+
- lib/any_cache/drivers/redis.rb
|
204
|
+
- lib/any_cache/drivers/redis_store.rb
|
195
205
|
- lib/any_cache/error.rb
|
196
206
|
- lib/any_cache/version.rb
|
197
207
|
homepage: https://github.com/0exp/any_cache
|