Module: Samurai::CacheableByToken

Included in:
PaymentMethod, Transaction
Defined in:
lib/samurai/cacheable_by_token.rb

Overview

Module for enabling caching of ActiveResource classes by token Essentially functions as a simple Identity Map

Defined Under Namespace

Modules: ClassExtensions

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

The default cache stores the values for the duration of the request Different caching strategies can be employed to keep the data around longer:

* class variables
* Rails.cache
* memcached
* redis cache


15
16
17
18
19
# File 'lib/samurai/cacheable_by_token.rb', line 15

def self.included(klass)
  klass.send :cattr_accessor, :cache
  klass.send :cache=, {}
  klass.extend(ClassExtensions)
end

Instance Method Details

#saveObject

Overrides the ActiveResource ‘save` method to update the current model in the cache



38
39
40
41
42
# File 'lib/samurai/cacheable_by_token.rb', line 38

def save
  super
  # update self in the cache
  self.class.cache[self.id] = self
end