Class: Tr8n::CacheAdapters::Rails
- Inherits:
-
Tr8n::Cache
- Object
- Tr8n::Cache
- Tr8n::CacheAdapters::Rails
- Defined in:
- lib/tr8n/cache_adapters/rails.rb
Instance Method Summary collapse
- #cache_name ⇒ Object
- #clear(opts = {}) ⇒ Object
- #delete(key, opts = {}) ⇒ Object
- #exist?(key, opts = {}) ⇒ Boolean
- #fetch(key, opts = {}) ⇒ Object
-
#initialize ⇒ Rails
constructor
A new instance of Rails.
- #read_only? ⇒ Boolean
- #store(key, data, opts = {}) ⇒ Object
Constructor Details
Instance Method Details
#cache_name ⇒ Object
42 43 44 |
# File 'lib/tr8n/cache_adapters/rails.rb', line 42 def cache_name @cache.class.name end |
#clear(opts = {}) ⇒ Object
95 96 97 98 99 |
# File 'lib/tr8n/cache_adapters/rails.rb', line 95 def clear(opts = {}) info("Cache clear") rescue Exception => ex warn("Failed to clear cache: #{ex.}") end |
#delete(key, opts = {}) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/tr8n/cache_adapters/rails.rb', line 78 def delete(key, opts = {}) info("Cache delete: #{key}") @cache.delete(versioned_key(key, opts)) key rescue Exception => ex warn("Failed to delete data: #{ex.}") key end |
#exist?(key, opts = {}) ⇒ Boolean
87 88 89 90 91 92 93 |
# File 'lib/tr8n/cache_adapters/rails.rb', line 87 def exist?(key, opts = {}) data = @cache.fetch(versioned_key(key, opts)) not data.nil? rescue Exception => ex warn("Failed to check if key exists: #{ex.}") false end |
#fetch(key, opts = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/tr8n/cache_adapters/rails.rb', line 50 def fetch(key, opts = {}) miss = false data = @cache.fetch(versioned_key(key, opts)) do info("Cache miss: #{key}") miss = true if block_given? yield else nil end end info("Cache hit: #{key}") unless miss data rescue Exception => ex warn("Failed to retrieve data: #{ex.}") return nil unless block_given? yield end |
#read_only? ⇒ Boolean
46 47 48 |
# File 'lib/tr8n/cache_adapters/rails.rb', line 46 def read_only? false end |
#store(key, data, opts = {}) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/tr8n/cache_adapters/rails.rb', line 69 def store(key, data, opts = {}) info("Cache store: #{key}") @cache.write(versioned_key(key, opts), data) data rescue Exception => ex warn("Failed to store data: #{ex.}") key end |