Class: IdentityCache::CacheFetcher
- Inherits:
-
Object
- Object
- IdentityCache::CacheFetcher
- Defined in:
- lib/identity_cache/cache_fetcher.rb
Instance Attribute Summary collapse
-
#cache_backend ⇒ Object
Returns the value of attribute cache_backend.
Instance Method Summary collapse
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #fetch(key) ⇒ Object
- #fetch_multi(keys, &block) ⇒ Object
-
#initialize(cache_backend) ⇒ CacheFetcher
constructor
A new instance of CacheFetcher.
- #write(key, value) ⇒ Object
Constructor Details
#initialize(cache_backend) ⇒ CacheFetcher
Returns a new instance of CacheFetcher.
5 6 7 |
# File 'lib/identity_cache/cache_fetcher.rb', line 5 def initialize(cache_backend) @cache_backend = cache_backend end |
Instance Attribute Details
#cache_backend ⇒ Object
Returns the value of attribute cache_backend.
3 4 5 |
# File 'lib/identity_cache/cache_fetcher.rb', line 3 def cache_backend @cache_backend end |
Instance Method Details
#clear ⇒ Object
17 18 19 |
# File 'lib/identity_cache/cache_fetcher.rb', line 17 def clear @cache_backend.clear end |
#delete(key) ⇒ Object
13 14 15 |
# File 'lib/identity_cache/cache_fetcher.rb', line 13 def delete(key) @cache_backend.write(key, IdentityCache::DELETED, :expires_in => IdentityCache::DELETED_TTL.seconds) end |
#fetch(key) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/identity_cache/cache_fetcher.rb', line 27 def fetch(key) result = nil yielded = false @cache_backend.cas(key) do |value| yielded = true unless IdentityCache::DELETED == value result = value break end result = yield break unless IdentityCache.should_fill_cache? result end unless yielded result = yield add(key, result) end result end |
#fetch_multi(keys, &block) ⇒ Object
21 22 23 24 25 |
# File 'lib/identity_cache/cache_fetcher.rb', line 21 def fetch_multi(keys, &block) results = cas_multi(keys, &block) results = add_multi(keys, &block) if results.nil? results end |
#write(key, value) ⇒ Object
9 10 11 |
# File 'lib/identity_cache/cache_fetcher.rb', line 9 def write(key, value) @cache_backend.write(key, value) if IdentityCache.should_fill_cache? end |