class Roadie::CachedProvider
end
end
stylesheet # You need to return the set Stylesheet
memcache.write(“assets/#{path}/name”, stylesheet.name)
memcache.write(“assets/#{path}/css”, stylesheet.to_s)
def []=(path, stylesheet)
end
end
Roadie::Stylesheet.new(name, css)
name = memcache.read(“assets/#{path}/name”) || “cached #{path}”
if css
css = memcache.read(“assets/#{path}/css”)
def [](path)
end
@memcache = memcache
def initialize(memcache)
class MyRoadieMemcacheStore
@example Custom cache store
provider = Roadie::CachedProvider.new(slow_provider, Application.asset_cache)
slow_provider = MyDatabaseProvider.new(Application)
Application.asset_cache = Hash.new
@example Global cache
return the instance again.
retrieve and set entries, respectively. The ‘#[name]=` method also needs to
instances when fetched. It must respond to `#[name]` and `#[name]=` to
The cache store must accept {Roadie::Stylesheet} instances, and return such
providers with very slow failures.
class in the future if there is a need for it. Remember this if you have
Not found assets are not cached currently, but it’s possible to extend this
cache to grow without bounds, which a shared hash would do.
instances, pass your own hash-like object. Just remember to not allow this
entire duration of the instance. If you want to share hash between
The default cache store is a instance-specific hash that lives for the
the response from it.
The {CachedProvider} wraps another provider (or {ProviderList}) and caches
@api public
def cache_fetch(name)
def cache_fetch(name) cache[name] || cache[name] = yield rescue CssNotFound cache[name] = nil raise end
def find_stylesheet(name)
def find_stylesheet(name) cache_fetch(name) do @upstream.find_stylesheet(name) end end
def find_stylesheet!(name)
def find_stylesheet!(name) cache_fetch(name) do @upstream.find_stylesheet!(name) end end
def initialize(upstream, cache = {})
-
cache
(#[], #[]=
) -- The cache store to use. -
upstream
(an asset provider
) -- The wrapped asset provider
def initialize(upstream, cache = {}) @upstream = upstream @cache = cache end