Sha256: 019600ce740cba14d7c2ae2c255d1ff3b7ecd289b294ee0f217dd1e1e4e6d371
Contents?: true
Size: 1.77 KB
Versions: 4
Compression:
Stored size: 1.77 KB
Contents
module RailsConnector # This module provides advances auto-invalidating caching mechanism for storing obj data. # # To keep it up-to-date its caches and changes should be updated periodically # It's changes should be updated every time a new workspace data has been fetched. # It's caches should be updated every time a new obj data has been fetched. module ContentStateCaching class << self # How deep should a content state chain be inspected. Default depth is 20. attr_accessor :cache_lookup_depth # At which lookup depth to copy a hit found in an ancestor content state # to the current content state's cache. Default depth is 5. attr_accessor :cache_replication_depth # Updates caches with data from given workspace. # Should be called every time a new OBJ data has been fetched. def store_obj_data(content_state, index, key, data) content_state.save_obj_data(index, key, data) if content_state end # Fetches up-to-date obj data for given workspace, index and key. # Returns nil if no up-to-date data found. def find_obj_data(current_content_state , index, key) if index == 'permalink' current_content_state.find_obj_data(index, key) else visitor = ContentStateVisitor.new(current_content_state) cache_lookup_depth.times do |depth| return unless content_state = visitor.visit_next if hit = content_state.find_obj_data(index, key) visitor.visited_except_current.each { |cs| return if cs.has_changes_for?(index, key, hit) } current_content_state.save_obj_data(index, key, hit) if depth >= cache_replication_depth return hit end end nil end end end self.cache_replication_depth = 5 self.cache_lookup_depth = 20 end end
Version data entries
4 entries across 4 versions & 1 rubygems