module RedisPage::ViewHelpers
Public Instance Methods
c(object_or_clazz)
click to toggle source
记录当前实体相关的页面,方便实体更新时,刷新页面缓存
# File lib/redis_page/view_helpers.rb, line 4 def c(object_or_clazz) if @page_need_to_cache && object_or_clazz object_or_clazz.is_a?(Class) ? mark_cache_clazz(object_or_clazz) : mark_cache_instance(object_or_clazz) end object_or_clazz end
mark_cache_clazz(clazz)
click to toggle source
记录类相关的页面,方便实体创建时,刷新页面缓存
# File lib/redis_page/view_helpers.rb, line 29 def mark_cache_clazz(clazz) name = clazz.table_name Rails.logger.info "[page cache]class: #{name}" RedisPage.cache_relation_redis.sadd("c:#{name}", { url: request.base_url + request.path, country: @cache_country }.to_json) end
mark_cache_instance(*array)
click to toggle source
记录当前实体相关的页面,方便实体更新时,刷新页面缓存 @params
-
object 直接传递实体对象
-
name, id 或者传递实体表名及id
# File lib/redis_page/view_helpers.rb, line 15 def mark_cache_instance(*array) name, id = array object = array.first if id name = name.downcase else name = object.class.table_name.downcase id = object.id end Rails.logger.info "[page cache]record: #{name}##{id}" RedisPage.cache_relation_redis.sadd("i:#{name}:#{id}", { url: request.base_url + request.path, country: @cache_country }.to_json) end