module RailsConnector # This module manages storage of different kind of cache data. module CmsCacheStorage VERSION = 'v1'.freeze class << self attr_writer :cache def cache @cache ||= begin prefix = VERSION.dup prefix.concat('-utf8') if String.new.encoding_aware? Cache.new(fallback_backend: backend_cache, cache_prefix: prefix) end end def backend_cache=(new_cache) @backend_cache = new_cache @cache = nil end def backend_cache @backend_cache || Rails.cache 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 end end end