Class: CacheManager::Key
- Inherits:
-
Object
- Object
- CacheManager::Key
- Defined in:
- app/models/cache_manager/key.rb
Constant Summary collapse
- EXCLUDED_DIRS =
['.', '..', 'assets'].freeze
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Class Method Summary collapse
Instance Method Summary collapse
- #all ⇒ Object
-
#initialize ⇒ Key
constructor
A new instance of Key.
- #keys_for_file_store ⇒ Object
- #keys_for_memory_store ⇒ Object
Constructor Details
#initialize ⇒ Key
Returns a new instance of Key.
7 8 9 |
# File 'app/models/cache_manager/key.rb', line 7 def initialize @klass = Rails.cache.class.to_s end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
5 6 7 |
# File 'app/models/cache_manager/key.rb', line 5 def klass @klass end |
Class Method Details
.all ⇒ Object
13 14 15 |
# File 'app/models/cache_manager/key.rb', line 13 def all new.all end |
.destroy(id) ⇒ Object
29 30 31 |
# File 'app/models/cache_manager/key.rb', line 29 def destroy(id) Rails.cache.delete(id) end |
.find(id) ⇒ Object
25 26 27 |
# File 'app/models/cache_manager/key.rb', line 25 def find(id) Rails.cache.read(id) end |
.flush(id) ⇒ Object
17 18 19 20 21 22 23 |
# File 'app/models/cache_manager/key.rb', line 17 def flush(id) if id == 'all' Rails.cache.clear else Rails.cache.delete(id) end end |
Instance Method Details
#all ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'app/models/cache_manager/key.rb', line 34 def all case @klass when 'ActiveSupport::Cache::FileStore' keys_for_file_store else keys_for_memory_store end end |
#keys_for_file_store ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'app/models/cache_manager/key.rb', line 47 def keys_for_file_store cache_path = Rails.cache.instance_variable_get(:'@cache_path') root_dirs = Dir.entries(cache_path).reject { |f| (EXCLUDED_DIRS + ['.gitkeep']).include?(f) } full_paths = root_dirs.collect { |i| cache_path + "#{i}" } full_paths.collect do |dir| File.basename(Dir["#{dir}/*/*"][0]) if Dir["#{dir}/*/*"][0] end end |
#keys_for_memory_store ⇒ Object
43 44 45 |
# File 'app/models/cache_manager/key.rb', line 43 def keys_for_memory_store Rails.cache.instance_variable_get(:@data).keys end |