Class: IdentityCache::CacheFetcher
- Inherits:
-
Object
- Object
- IdentityCache::CacheFetcher
- Defined in:
- lib/identity_cache/cache_fetcher.rb
Defined Under Namespace
Classes: FillLock
Constant Summary collapse
- EMPTY_HASH =
{}.freeze
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, fill_lock_duration: nil, lock_wait_tries: 2, &block) ⇒ 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.
51 52 53 |
# File 'lib/identity_cache/cache_fetcher.rb', line 51 def initialize(cache_backend) @cache_backend = cache_backend end |
Instance Attribute Details
#cache_backend ⇒ Object
Returns the value of attribute cache_backend.
7 8 9 |
# File 'lib/identity_cache/cache_fetcher.rb', line 7 def cache_backend @cache_backend end |
Instance Method Details
#clear ⇒ Object
63 64 65 |
# File 'lib/identity_cache/cache_fetcher.rb', line 63 def clear @cache_backend.clear end |
#delete(key) ⇒ Object
59 60 61 |
# File 'lib/identity_cache/cache_fetcher.rb', line 59 def delete(key) @cache_backend.write(key, IdentityCache::DELETED, expires_in: IdentityCache::DELETED_TTL.seconds) end |
#fetch(key, fill_lock_duration: nil, lock_wait_tries: 2, &block) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/identity_cache/cache_fetcher.rb', line 77 def fetch(key, fill_lock_duration: nil, lock_wait_tries: 2, &block) if fill_lock_duration && IdentityCache.should_fill_cache? fetch_with_fill_lock(key, fill_lock_duration, lock_wait_tries, &block) else fetch_without_fill_lock(key, &block) end end |
#fetch_multi(keys, &block) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/identity_cache/cache_fetcher.rb', line 67 def fetch_multi(keys, &block) if IdentityCache.should_use_cache? results = cas_multi(keys, &block) results = add_multi(keys, &block) if results.nil? results else {} end end |
#write(key, value) ⇒ Object
55 56 57 |
# File 'lib/identity_cache/cache_fetcher.rb', line 55 def write(key, value) @cache_backend.write(key, value) if IdentityCache.should_fill_cache? end |