Class: WurflCloud::Cache::Rails

Inherits:
Object
  • Object
show all
Defined in:
lib/wurfl_cloud/cache/rails.rb

Instance Method Summary collapse

Constructor Details

#initialize(options, environment) ⇒ Rails

Returns a new instance of Rails.



17
18
19
# File 'lib/wurfl_cloud/cache/rails.rb', line 17

def initialize(options, environment)
  @prefix = options[:prefix]||''
end

Instance Method Details

#[](key) ⇒ Object

Should return the value stored for the key, nil if the key is not in cache The Rails cache reads from the Rails.cache object



46
47
48
# File 'lib/wurfl_cloud/cache/rails.rb', line 46

def [](key)
  ::Rails.cache.read("#{key_prefix}#{Digest::MD5.hexdigest(key)}")
end

#[]=(key, value) ⇒ Object

Stores the value for the key in the Rails.cache



51
52
53
# File 'lib/wurfl_cloud/cache/rails.rb', line 51

def []=(key, value)
  ::Rails.cache.write("#{key_prefix}#{Digest::MD5.hexdigest(key)}", value)
end

#key_prefixObject



25
26
27
# File 'lib/wurfl_cloud/cache/rails.rb', line 25

def key_prefix        
  "#{prefix}:#{mtime}:"
end

#mtimeObject



29
30
31
# File 'lib/wurfl_cloud/cache/rails.rb', line 29

def mtime
  ::Rails.cache.read("#{prefix}mtime")
end

#mtime=(new_mtime) ⇒ Object



33
34
35
# File 'lib/wurfl_cloud/cache/rails.rb', line 33

def mtime=(new_mtime)
  ::Rails.cache.write("#{prefix}mtime", new_mtime)
end

#prefixObject



21
22
23
# File 'lib/wurfl_cloud/cache/rails.rb', line 21

def prefix
  "#{(@prefix.nil? || @prefix=="") ? "": "#{@prefix}:"}"
end

#validate(current_mtime) ⇒ Object

Validates the cache checks if the cache is still valid with respect to a new mtime received from the server if the new mtime is different from the one cached then it overwrites the current key prefix thus actually invalidationg the cache



41
42
# File 'lib/wurfl_cloud/cache/rails.rb', line 41

def validate(current_mtime)
end