level2 0.2.2 → 0.2.3
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/Gemfile.lock +1 -1
- data/README.md +22 -7
- data/level2.gemspec +1 -1
- data/lib/active_support/cache/level2.rb +13 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55484925ce4a257280cf6b5762d994c5060a3407
|
4
|
+
data.tar.gz: d0e5db0b945eb2b3ec842e3ea27521ba4babb598
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5a18e2485138ecf6c248c134fb53567e79be45e6f62f282d56eadba34d0e0cd4a0d1a1eafcd6df3b609eb3dce6f083afe20780d6a4428eea0e2ffdfa773fc3f
|
7
|
+
data.tar.gz: a4b765d0b04f03a2887616e4d90bf920a61b29fdfbe7d534e0e6a11fa178250149696b48e8ffdd1048318bd50bcab2be5600e8f0ea60824b86a532814da6b293
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -50,15 +50,30 @@ Example:
|
|
50
50
|
```ruby
|
51
51
|
# in config/application.rb
|
52
52
|
|
53
|
-
config.cache_store = :level2,
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
L2: [
|
58
|
-
:mem_cache_store, 'host1.example.org:11211'
|
59
|
-
]
|
53
|
+
config.cache_store = :level2, {
|
54
|
+
L1: [ :memory_store, size: 32.megabytes ],
|
55
|
+
L2: [ :mem_cache_store, 'host1.example.org:11211' ]
|
56
|
+
}
|
60
57
|
```
|
61
58
|
|
59
|
+
From thereon,
|
60
|
+
|
61
|
+
- `Rails.cache.read` and `.fetch` will read from `L1` and fall back to `L2` if
|
62
|
+
the key is absent from `L1`.
|
63
|
+
When reading from `L2`, `L1` will get populated automatically on misses.
|
64
|
+
- `Rails.cache.write` and `.fetch` will write to both stores.
|
65
|
+
|
66
|
+
While discouraged, it is possible to write directly to a given cache level:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
Rails.cache.write('foo', 'bar', only: :L2)
|
70
|
+
```
|
71
|
+
|
72
|
+
This can be useful in cases where `L1` is a non-shared cache (e.g. in-memory
|
73
|
+
cache) and `L2` is shared (e.g. Redis, Memcached); and you want to keep the
|
74
|
+
ability to bust the cache manually.
|
75
|
+
|
76
|
+
|
62
77
|
## Notifications
|
63
78
|
|
64
79
|
Level2 enriches
|
data/level2.gemspec
CHANGED
@@ -35,14 +35,16 @@ module ActiveSupport
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def read_entry(key, options)
|
38
|
+
stores = selected_stores(options)
|
38
39
|
@lock.synchronize do
|
39
|
-
read_entry_from(
|
40
|
+
read_entry_from(stores, key, options)
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
43
44
|
def write_entry(key, entry, options)
|
45
|
+
stores = selected_stores(options)
|
44
46
|
@lock.synchronize do
|
45
|
-
|
47
|
+
stores.each do |name, store|
|
46
48
|
result = store.send :write_entry, key, entry, options
|
47
49
|
return false unless result
|
48
50
|
end
|
@@ -51,8 +53,9 @@ module ActiveSupport
|
|
51
53
|
end
|
52
54
|
|
53
55
|
def delete_entry(key, options)
|
56
|
+
selected_stores(options)
|
54
57
|
@lock.synchronize do
|
55
|
-
|
58
|
+
stores.map { |name,store|
|
56
59
|
store.send :delete_entry, key, options
|
57
60
|
}.all?
|
58
61
|
end
|
@@ -82,6 +85,13 @@ module ActiveSupport
|
|
82
85
|
|
83
86
|
entry
|
84
87
|
end
|
88
|
+
|
89
|
+
def selected_stores(options)
|
90
|
+
only = options[:only]
|
91
|
+
return @stores if only.nil?
|
92
|
+
@stores.select { |name,_| name == only }
|
93
|
+
end
|
94
|
+
|
85
95
|
end
|
86
96
|
end
|
87
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: level2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julien Letessier
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|