Module: RedisPage::ViewHelpers

Defined in:
lib/redis_page/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#c(object_or_clazz) ⇒ Object

记录当前实体相关的页面,方便实体更新时,刷新页面缓存



4
5
6
7
8
9
# 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) ⇒ Object

记录类相关的页面,方便实体创建时,刷新页面缓存



29
30
31
32
33
# 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) ⇒ Object

记录当前实体相关的页面,方便实体更新时,刷新页面缓存

  1. object 直接传递实体对象

  2. name, id 或者传递实体表名及id



15
16
17
18
19
20
21
22
23
24
25
26
# 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