Class: Roadie::CachedProvider
- Inherits:
-
Object
- Object
- Roadie::CachedProvider
- Defined in:
- lib/roadie/cached_provider.rb
Overview
The CachedProvider wraps another provider (or ProviderList) and caches the response from it.
The default cache store is a instance-specific hash that lives for the entire duration of the instance. If you want to share hash between instances, pass your own hash-like object. Just remember to not allow this cache to grow without bounds, which a shared hash would do.
Not found assets are not cached currently, but it’s possible to extend this class in the future if there is a need for it. Remember this if you have providers with very slow failures.
The cache store must accept Stylesheet instances, and return such instances when fetched. It must respond to ‘#[name]` and `#[name]=` to retrieve and set entries, respectively. The `#[name]=` method also needs to return the instance again.
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
The cache store used by this instance.
Instance Method Summary collapse
- #find_stylesheet(name) ⇒ Object
- #find_stylesheet!(name) ⇒ Object
-
#initialize(upstream, cache = {}) ⇒ CachedProvider
constructor
A new instance of CachedProvider.
Constructor Details
#initialize(upstream, cache = {}) ⇒ CachedProvider
Returns a new instance of CachedProvider.
52 53 54 55 |
# File 'lib/roadie/cached_provider.rb', line 52 def initialize(upstream, cache = {}) @upstream = upstream @cache = cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
The cache store used by this instance.
48 49 50 |
# File 'lib/roadie/cached_provider.rb', line 48 def cache @cache end |
Instance Method Details
#find_stylesheet(name) ⇒ Object
57 58 59 60 61 |
# File 'lib/roadie/cached_provider.rb', line 57 def find_stylesheet(name) cache_fetch(name) do @upstream.find_stylesheet(name) end end |
#find_stylesheet!(name) ⇒ Object
63 64 65 66 67 |
# File 'lib/roadie/cached_provider.rb', line 63 def find_stylesheet!(name) cache_fetch(name) do @upstream.find_stylesheet!(name) end end |