Class: ActiveSupport::Cache::ActiveRecordStore
- Inherits:
-
Store
- Object
- Store
- ActiveSupport::Cache::ActiveRecordStore
- Defined in:
- lib/active_support/cache/active_record_store.rb
Defined Under Namespace
Classes: CacheItem
Constant Summary collapse
- VERSION =
"0.0.3"
- ITEMS_LIMIT =
do not allow to store more items than
5000
Instance Method Summary collapse
- #clear ⇒ Object
- #debug_mode? ⇒ Boolean
- #delete_entry(key, options) ⇒ Object
- #read_entry(key, options = {}) ⇒ Object
- #write_entry(key, entry, options) ⇒ Object
Instance Method Details
#clear ⇒ Object
53 54 55 |
# File 'lib/active_support/cache/active_record_store.rb', line 53 def clear CacheItem.delete_all end |
#debug_mode? ⇒ Boolean
84 85 86 |
# File 'lib/active_support/cache/active_record_store.rb', line 84 def debug_mode? ENV['ACTIVE_RECORD_CACHE_STORE_DEBUG_MODE'] == "1" end |
#delete_entry(key, options) ⇒ Object
57 58 59 |
# File 'lib/active_support/cache/active_record_store.rb', line 57 def delete_entry(key, ) CacheItem.delete_all(:key => key) end |
#read_entry(key, options = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/active_support/cache/active_record_store.rb', line 61 def read_entry(key, ={}) item = CacheItem.find_by_key(key) if item.present? && debug_mode? item.[:access_counter] += 1 item.[:access_time] = Time.now item.save end item end |
#write_entry(key, entry, options) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/active_support/cache/active_record_store.rb', line 73 def write_entry(key, entry, ) = .clone.symbolize_keys item = CacheItem.find_or_initialize_by_key(key) item.debug_mode = debug_mode? item.value = entry.value item.expires_at = [:expires_in].try(:since) item.save free_some_space end |