level2 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd22a879fc709547670d6087d4d6c0df6d760cd5
4
- data.tar.gz: '0910c7bd2cc02bf0fb1177e61c5b2fe11e222ad7'
3
+ metadata.gz: 55484925ce4a257280cf6b5762d994c5060a3407
4
+ data.tar.gz: d0e5db0b945eb2b3ec842e3ea27521ba4babb598
5
5
  SHA512:
6
- metadata.gz: a94dcd0ec43f22836b52d905b3eeedfa2267058c28ee1a8b02781da438bfc7df70b2460126801e3c1a0df821d28f3a1bcde88b2c8c1bc036936f81d963f76c2b
7
- data.tar.gz: 5e50a036eff055d6ab5c81d3b77f69ed3548a6b42610d468b600cf12c553acca0779cbcb08c5be4b4ad7228397e72ad42d6862ea0f9c335c40d4432e5b8fb76f
6
+ metadata.gz: c5a18e2485138ecf6c248c134fb53567e79be45e6f62f282d56eadba34d0e0cd4a0d1a1eafcd6df3b609eb3dce6f083afe20780d6a4428eea0e2ffdfa773fc3f
7
+ data.tar.gz: a4b765d0b04f03a2887616e4d90bf920a61b29fdfbe7d534e0e6a11fa178250149696b48e8ffdd1048318bd50bcab2be5600e8f0ea60824b86a532814da6b293
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- level2 (0.2.2)
4
+ level2 (0.2.3)
5
5
  activesupport (~> 4)
6
6
 
7
7
  GEM
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
- L1: [
55
- :memory_store, size: 32.megabytes
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
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'level2'
7
- spec.version = '0.2.2'
7
+ spec.version = '0.2.3'
8
8
  spec.authors = ['Julien Letessier']
9
9
  spec.email = ['julien.letessier@gmail.com']
10
10
 
@@ -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(@stores, key, options)
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
- @stores.each do |name, store|
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
- @stores.map { |name,store|
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.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-10 00:00:00.000000000 Z
11
+ date: 2016-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler