module Scrivito # This module manages storage of different kind of cache data. module CmsDataCache VERSION = 'v2'.freeze class << self attr_reader :second_level_cache attr_writer :cache_path def cache @cache_chain ||= Cache::RamStore.new(next_store: first_level_cache, cache_prefix: VERSION) end def cache_path=(path) clear_cache_chain @cache_path = path end def first_level_cache @first_level_cache ||= Cache::FileStore.new(path: @cache_path, next_store: second_level_cache) end def second_level_cache=(cache_store) clear_cache_chain @second_level_cache = cache_store end def read_workspace_data(workspace_id) cache.read("workspace/#{workspace_id}") end def write_workspace_data(workspace_id, workspace_data) cache.write("workspace/#{workspace_id}", workspace_data) end def read_content_state(content_state_id) cache.read("content/#{content_state_id}") end def write_content_state(content_state_id, content_state) cache.write("content/#{content_state_id}", content_state) end def read_obj_data(content_state_id, index, key) cache.read("content/#{content_state_id}/obj/#{index}/#{key}") end def write_obj_data(content_state_id, index, key, data) cache.write("content/#{content_state_id}/obj/#{index}/#{key}", data) end def read_obj_classes_data(content_state_id) cache.read("content/#{content_state_id}/obj_classes") end def write_obj_classes_data(content_state_id, data) cache.write("content/#{content_state_id}/obj_classes", data) end private def clear_cache_chain @cache_chain = nil @first_level_cache = nil @second_level_cache = nil end end end end