Class: Exchange::Cache::Rails
Overview
A class that cooperates with rails to cache the data from the exchange api in rails
Instance Method Summary collapse
-
#cached(api, opts = {}) { ... } ⇒ Object
returns either cached data from the memcached client or calls the block and caches it in rails cache.
-
#client ⇒ ActiveSupport::Cache::Subclass
returns a Rails cache client.
Instance Method Details
#cached(api, opts = {}) { ... } ⇒ Object
returns either cached data from the memcached client or calls the block and caches it in rails cache. This method has to be the same in all the cache classes in order for the configuration binding to work
35 36 37 38 39 40 41 42 |
# File 'lib/exchange/cache/rails.rb', line 35 def cached api, opts={}, &block raise_caching_needs_block! unless block_given? result = client.fetch key(api, opts), :expires_in => config.expire == :daily ? 86400 : 3600, &block client.delete(key(api, opts)) unless result && !result.to_s.empty? result end |
#client ⇒ ActiveSupport::Cache::Subclass
returns a Rails cache client. This has not to be stored since rails already memoizes it. Use this client to access rails cache data. For further explanation of use visit the rails documentation
22 23 24 25 |
# File 'lib/exchange/cache/rails.rb', line 22 def client Exchange::GemLoader.new('rails').try_load unless defined?(::Rails) ::Rails.cache end |