Class: FindCache::KeyGen
- Inherits:
-
Object
- Object
- FindCache::KeyGen
- Defined in:
- lib/find_cache/key_gen.rb
Class Method Summary collapse
-
.cache_key(model_name, id) ⇒ Object
cache_key generator for model items.
-
.cache_key_ref(model_name, foreign_key_name, foreign_key_id) ⇒ Object
cache_key generator for model items with referenced attribute.
-
.clear_find_cache_store ⇒ Object
Cleaning all caches of the current Thread not the Rails.cache.
-
.global_cache_key(clear = false) ⇒ Object
cache_key generator for the current thread.
Class Method Details
.cache_key(model_name, id) ⇒ Object
16 17 18 |
# File 'lib/find_cache/key_gen.rb', line 16 def self.cache_key(model_name, id) "#{model_name}/#{id}" end |
.cache_key_ref(model_name, foreign_key_name, foreign_key_id) ⇒ Object
31 32 33 |
# File 'lib/find_cache/key_gen.rb', line 31 def self.cache_key_ref(model_name, foreign_key_name, foreign_key_id) "#{model_name}/#{foreign_key_name}-#{foreign_key_id}" end |
.clear_find_cache_store ⇒ Object
Cleaning all caches of the current Thread not the Rails.cache
58 59 60 61 |
# File 'lib/find_cache/key_gen.rb', line 58 def self.clear_find_cache_store $find_cache_store.delete(KeyGen.global_cache_key) KeyGen.global_cache_key(true) end |
.global_cache_key(clear = false) ⇒ Object
cache_key generator for the current thread
Parameters
-
clear
- Boolean value to clean up the current Thread’s cache key
Examples
# For generating cache key for the current Thread
FindCache::KeyGen.global_cache_key
# For cleaning generated cache key for the current Thread
FindCache::KeyGen.global_cache_key(true)
47 48 49 50 51 52 53 54 |
# File 'lib/find_cache/key_gen.rb', line 47 def self.global_cache_key(clear = false) return (Thread.current[:global_cache_key] = nil) if clear Thread.current[:global_cache_key] ||= ( t = SimpleUUID::UUID.new(Time.now).to_i.to_s(16).rjust(32, "0") $find_cache_store[t] = {} t ) end |