Class: Arena::Cache::Adaptor::Rails

Inherits:
Generic
  • Object
show all
Defined in:
lib/arena/cache/adaptor/rails.rb

Instance Attribute Summary

Attributes included from Arena::Configurable

#access_token, #api_version, #application_id, #application_secret, #auth_token, #base_domain, #expires_in, #use_caching

Class Method Summary collapse

Methods included from Arena::Configurable

#configure, keys, #reset!

Class Method Details

.method_missing(method, *args, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/arena/cache/adaptor/rails.rb', line 7

def self.method_missing(method, *args, &block)
  # Brittle/ugly but works for the time being
  # 
  key = args.present? ? "arena_#{method}_#{args.first}" : "arena_#{method}"
  cache = Rails.cache.read(key)

  if cache.nil?
    object = args.present? ? Arena.send(method, args.first) : Arena.send(method)
    
    Rails.cache.write(key, object, expires_in: Arena.expires_in)
    
    cache = Rails.cache.read(key)
  end

  cache
end