Class: WurflCloud::Cache::Rails
- Inherits:
-
Object
- Object
- WurflCloud::Cache::Rails
- Defined in:
- lib/wurfl_cloud/cache/rails.rb
Instance Method Summary collapse
-
#[](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.
-
#[]=(key, value) ⇒ Object
Stores the value for the key in the Rails.cache.
-
#initialize(options, environment) ⇒ Rails
constructor
A new instance of Rails.
- #key_prefix ⇒ Object
- #mtime ⇒ Object
- #mtime=(new_mtime) ⇒ Object
- #prefix ⇒ Object
-
#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.
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(, environment) @prefix = [: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_prefix ⇒ Object
25 26 27 |
# File 'lib/wurfl_cloud/cache/rails.rb', line 25 def key_prefix "#{prefix}:#{mtime}:" end |
#mtime ⇒ Object
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 |
#prefix ⇒ Object
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 |