module Card::Cache::All

cache-related instance methods available to all Cards

Public Instance Methods

ensure_view_cache_key(cache_key) click to toggle source
# File lib/card/cache/all.rb, line 30
def ensure_view_cache_key cache_key
  return if view_cache_keys.include? cache_key

  view_cache_keys << cache_key
  shared_write_view_cache_keys
end
expire(cache_type=nil) click to toggle source
# File lib/card/cache/all.rb, line 17
def expire cache_type=nil
  return unless (cache_class = cache_class_from_type cache_type)

  expire_views
  expire_names cache_class
  expire_id cache_class
  expire_left cache_type
end
lex() click to toggle source
# File lib/card/cache/all.rb, line 9
def lex
  if simple?
    name
  elsif left_id && right_id
    [left_id, right_id]
  end
end
view_cache_clean?() click to toggle source
# File lib/card/cache/all.rb, line 26
def view_cache_clean?
  !db_content_changed?
end
write_lexicon() click to toggle source
# File lib/card/cache/all.rb, line 5
def write_lexicon
  Lexicon.write_to_temp_cache id, name, lex
end

Private Instance Methods

cache_class_from_type(cache_type) click to toggle source
# File lib/card/cache/all.rb, line 58
def cache_class_from_type cache_type
  cache_type ? Card.cache.send(cache_type) : Card.cache
end
each_key_version() { |to_name.key| ... } click to toggle source
# File lib/card/cache/all.rb, line 104
def each_key_version
  [name, name_before_act].uniq.compact.each do |name_version|
    yield name_version.to_name.key
  end
end
expire_id(cache) click to toggle source
# File lib/card/cache/all.rb, line 92
def expire_id cache
  return unless id.present?

  cache.delete "~#{id}"
end
expire_left(cache_type) click to toggle source
# File lib/card/cache/all.rb, line 39
def expire_left cache_type
  return unless name.compound? && expire_left?

  Card.cache.read(name.left_name.key)&.expire cache_type
end
expire_left?() click to toggle source
# File lib/card/cache/all.rb, line 45
def expire_left?
  true
end
expire_name(name_version, cache) click to toggle source
# File lib/card/cache/all.rb, line 72
def expire_name name_version, cache
  return unless name_version.present?

  key_version = name_version.to_name.key
  return unless key_version.present?

  cache.delete key_version
end
expire_names(cache) click to toggle source
# File lib/card/cache/all.rb, line 66
def expire_names cache
  each_key_version do |key_version|
    expire_name key_version, cache
  end
end
expire_view_cache_keys(view_keys) click to toggle source
# File lib/card/cache/all.rb, line 98
def expire_view_cache_keys view_keys
  Array.wrap(view_keys).each do |view_key|
    Card::View.cache.delete view_key
  end
end
expire_views() click to toggle source
# File lib/card/cache/all.rb, line 81
def expire_views
  each_key_version do |key|
    # puts "EXPIRE VIEW CACHE (#{name}): #{view_cache_keys}"
    view_keys = shared_read_view_cache_keys key
    next unless view_keys.present?

    expire_view_cache_keys view_keys
  end
  @view_cache_keys = []
end
shared_read_view_cache_keys(key_root=key) click to toggle source
# File lib/card/cache/all.rb, line 49
def shared_read_view_cache_keys key_root=key
  Card.cache.shared&.read_attribute key_root, :view_cache_keys
end
shared_write_view_cache_keys() click to toggle source
# File lib/card/cache/all.rb, line 53
def shared_write_view_cache_keys
  # puts "WRITE VIEW CACHE KEYS (#{name}): #{view_cache_keys}"
  Card.cache.shared&.write_attribute key, :view_cache_keys, view_cache_keys
end
view_cache_keys() click to toggle source
# File lib/card/cache/all.rb, line 62
def view_cache_keys
  @view_cache_keys ||= shared_read_view_cache_keys(key) || []
end