Sha256: fa2b24b9950d392c332944b8587597e55f2e7f1202ce0852c2e614f21a2d5da9

Contents?: true

Size: 1.77 KB

Versions: 27

Compression:

Stored size: 1.77 KB

Contents

module Scrivito

# 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
# Its changes should be updated every time a new workspace data has been fetched.
# Its 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

27 entries across 27 versions & 1 rubygems

Version Path
scrivito_sdk-1.0.0 lib/scrivito/content_state_caching.rb
scrivito_sdk-1.0.0.rc4 lib/scrivito/content_state_caching.rb
scrivito_sdk-1.0.0.rc3 lib/scrivito/content_state_caching.rb
scrivito_sdk-1.0.0.rc2 lib/scrivito/content_state_caching.rb
scrivito_sdk-1.0.0.rc1 lib/scrivito/content_state_caching.rb
scrivito_sdk-0.90.0 lib/scrivito/content_state_caching.rb
scrivito_sdk-0.90.0.rc3 lib/scrivito/content_state_caching.rb
scrivito_sdk-0.90.0.rc2 lib/scrivito/content_state_caching.rb
scrivito_sdk-0.90.0.rc1 lib/scrivito/content_state_caching.rb
scrivito_sdk-0.70.2 lib/scrivito/content_state_caching.rb
scrivito_sdk-0.71.2 lib/scrivito/content_state_caching.rb
scrivito_sdk-0.71.1 lib/scrivito/content_state_caching.rb
scrivito_sdk-0.70.1 lib/scrivito/content_state_caching.rb
scrivito_sdk-0.71.0 lib/scrivito/content_state_caching.rb
scrivito_sdk-0.71.0.rc2 lib/scrivito/content_state_caching.rb
scrivito_sdk-0.71.0.rc1 lib/scrivito/content_state_caching.rb
scrivito_sdk-0.70.0 lib/scrivito/content_state_caching.rb
scrivito_sdk-0.70.0.rc3 lib/scrivito/content_state_caching.rb
scrivito_sdk-0.70.0.rc2 lib/scrivito/content_state_caching.rb
scrivito_sdk-0.70.0.rc1 lib/scrivito/content_state_caching.rb