module ViewModel::ActiveRecord::Cache::CacheableView

Concern providing caching configuration and lookup on viewmodels.

Constants

CacheClearer
Callback handler to participate in ActiveRecord::ConnectionAdapters

Transaction callbacks: invalidates a given cache member after the current transaction commits.

Public Instance Methods

after_deserialize(deserialize_context:, changes:) click to toggle source

Clear the cache if the view or its nested children were changed during deserialization

Calls superclass method
# File lib/view_model/active_record/cache/cacheable_view.rb, line 46
def after_deserialize(deserialize_context:, changes:)
  super if defined?(super)

  if !changes.new? && changes.changed_nested_tree?
    CacheClearer.new(self.class.viewmodel_cache, id).add_to_transaction
  end
end
create_viewmodel_cache!(**opts) click to toggle source
# File lib/view_model/active_record/cache/cacheable_view.rb, line 35
def create_viewmodel_cache!(**opts)
  @viewmodel_cache = ViewModel::ActiveRecord::Cache.new(self, **opts)
end
viewmodel_cache() click to toggle source
# File lib/view_model/active_record/cache/cacheable_view.rb, line 39
def viewmodel_cache
  @viewmodel_cache
end