Module: Cachable
- Included in:
- ActiveResource::Connection
- Defined in:
- lib/cachable.rb
Overview
Caching is a way to speed up slow ActiveResource queries by keeping the result of a request around to be reused by subsequent requests.
Caching is turned OFF by default.
Usage
require 'cachable'
module CachedResource
class Base < ActiveResource::Base
end
class ActiveResource::Connection
include Cachable
end
end
Caching stores
All the caching stores from ActiveSupport::Cache are available as backends for caching. See the Rails rdoc for more information on these stores
Configuration examples (‘off’ is the default):
CachedResource.connection.cache_store = ActiveSupport::Cache.lookup_store :memory_store
CachedResource.connection.cache_store = ActiveSupport::Cache.lookup_store :file_store, "/path/to/cache/directory"
CachedResource.connection.cache_store = ActiveSupport::Cache.lookup_store :drb_store, "druby://localhost:9192"
CachedResource.connection.cache_store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost"
CachedResource.connection.cache_store = MyOwnStore.new("parameter")
If you are using a store that has write options, you can set them
CachedResource.connection. = { :expires_in => 60.seconds }
Note: To ensure that caching is turned off, set CachedResource.connection.cache_store = nil
FYI: You can use this with any active resource interface, not just Highrise.
Defined Under Namespace
Modules: InstanceMethods
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/cachable.rb', line 40 def self.included(base) base.class_eval do include InstanceMethods alias_method_chain :get, :cache end end |