Skip to content

Add a hook for ActiveRecord CRUD to automatically trigger a priming of the cache #29

@prpetten

Description

@prpetten
class FruitLoops < ApplicationRecord

  after_create :prime_cache, type: :create, serializer: ToucanSam
  after_update :prime_cache, type: :update, serializer: ToucanSam
  after_destroy :prime_cache, type: :destroy, serializer: ToucanSam

  # or possibly

  after_commit :prime_cache, serializer: ToucanSam
   ...
end

This way you would be invalidating your cache and creating a new one on every CRUD action so that you'd nearly always be getting a cached result from the serializer.

In concert with this functionality, it would be nice to have a rake task to prime all of the caches initially.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions