Module: TaggableCache::CacheStoreExtension

Extended by:
ActiveSupport::Concern
Defined in:
lib/taggable_cache/extensions/cache_store.rb

Instance Method Summary collapse

Instance Method Details

#add_tags(key, *params) ⇒ Object

Add tag to cache element



10
11
12
# File 'lib/taggable_cache/extensions/cache_store.rb', line 10

def add_tags(key, *params)
  taggable.add(key, *params)
end

#expire_allObject

Expire all cache entries availible for taggable WARNING: this is expensive function and may take VERY long on big data



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/taggable_cache/extensions/cache_store.rb', line 23

def expire_all
  #Load all the models
  Dir.glob(Rails.root + '/app/models/*.rb').each {|file| require file}
  
  ActiveRecord::Base.subclasses.each do |cls|
    expire_tags cls

    pk_name = cls.primary_key

    return if cls.unscoped.first.nil? #There is no sence in continuing, if model is empty

    last_id = cls.order(pk_name).last.try(pk_name.to_sym)

    #hardcoded value for first record
    first_id = 1

    (first_id..last_id).each do |id|
      expire_tags({:cls => cls, :id => id})
    end
  end
end

#expire_tags(*params) ⇒ Object

Expire cache elements by list of keys



15
16
17
18
19
# File 'lib/taggable_cache/extensions/cache_store.rb', line 15

def expire_tags(*params)
  taggable.get(*params).each do |m|
    self.delete(m)
  end
end

#taggableObject



5
6
7
# File 'lib/taggable_cache/extensions/cache_store.rb', line 5

def taggable
  @taggable ||= TaggableCache.new_store
end