Class: Cache
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cache
- Defined in:
- app/models/cache.rb
Class Method Summary collapse
-
.sweep(hash) ⇒ Object
We can provide a kpath selector for sweeping.
- .with(visitor_id, visitor_groups, kpath, *context) ⇒ Object
Class Method Details
.sweep(hash) ⇒ Object
We can provide a kpath selector for sweeping. If the kpath is in the cached scope, the cache is removed.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/cache.rb', line 26 def sweep(hash) return # if kpath = hash[:kpath] # klasses = [] # kpath.split(//).each_index { |i| klasses << kpath[0..i] } # kpath_selector = " AND kpath IN (#{klasses.map{|k| connection.quote(k)}.join(',')})" # else # kpath_selector = "" # end # if hash[:visitor_id] # self.connection.execute "DELETE FROM #{self.table_name} WHERE visitor_id = '#{hash[:visitor_id]}'" + kpath_selector # end # if hash[:visitor_groups] # hash[:visitor_groups].each do |g| # self.connection.execute "DELETE FROM #{self.table_name} WHERE visitor_groups LIKE '%.#{g}.%'" + kpath_selector # end # end # if hash[:context] # context = [hash[:context]].flatten.join('.').hash.abs # self.connection.execute "DELETE FROM #{self.table_name} WHERE context = '#{context}'" + kpath_selector # end # if hash[:older_than] # self.connection.execute "DELETE FROM #{self.table_name} WHERE updated_at < '#{hash[:older_than]}'" + kpath_selector # end end |
.with(visitor_id, visitor_groups, kpath, *context) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/models/cache.rb', line 11 def with(visitor_id, visitor_groups, kpath, *context) yield # return yield unless perform_caching # if cached = self.find(:first, :conditions => ["visitor_id = ? AND site_id = ? AND context = ?", visitor_id, visitor.site.id, context.join('.').hash.abs]) # cached[:content] # else # content = yield # self.create(:visitor_id=>visitor_id, :visitor_groups=>".#{visitor_groups.join('.')}.", :kpath=>kpath, # :context=>context.join('.').hash.abs, :content=>content ) # content # end end |