Class: Twingly::UrlCache
- Inherits:
-
Object
- Object
- Twingly::UrlCache
- Defined in:
- lib/twingly/url_cache.rb,
lib/twingly/url_cache/version.rb
Constant Summary collapse
- CACHE_VALUE =
""- VERSION =
"1.0.1"
Instance Attribute Summary collapse
-
#ttl ⇒ Object
readonly
Returns the value of attribute ttl.
Instance Method Summary collapse
- #cache!(url) ⇒ Object
- #cached?(url) ⇒ Boolean
-
#initialize(ttl: 0) ⇒ UrlCache
constructor
A new instance of UrlCache.
Constructor Details
#initialize(ttl: 0) ⇒ UrlCache
Returns a new instance of UrlCache.
12 13 14 15 |
# File 'lib/twingly/url_cache.rb', line 12 def initialize(ttl: 0) @cache = Dalli::Client.new(servers, ) @ttl = ttl end |
Instance Attribute Details
#ttl ⇒ Object (readonly)
Returns the value of attribute ttl.
8 9 10 |
# File 'lib/twingly/url_cache.rb', line 8 def ttl @ttl end |
Instance Method Details
#cache!(url) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/twingly/url_cache.rb', line 17 def cache!(url) key = key_for(url) Retryable.retryable(tries: 3, on: Dalli::RingError) do !!@cache.set(key, CACHE_VALUE, ttl, raw: true) end end |
#cached?(url) ⇒ Boolean
24 25 26 27 28 29 |
# File 'lib/twingly/url_cache.rb', line 24 def cached?(url) key = key_for(url) Retryable.retryable(tries: 3, on: Dalli::RingError) do @cache.get(key, raw: true) == CACHE_VALUE end end |