Cache Marks
An introduction of the pattern of using cache “marks” for use in building cache keys and indicating resource state uniqueness.
A cache mark is a simple value that represents a unique state of a resource or group of resources as a whole or in a particular context. A commonly used (but not referred to as) cache mark is a resource’s updated_at
timestamp. It is updated to the current time when a resource is updated allowing for cache keys that use that mark to automatically invalidate caches based on previous versions of that resource’s mark. In the case of a group of resources a mark may be used to invalidate keys whenever any member of the collection is modified or removed.
Cache marks must be stored separately from the resource itself when:
- a lookup of that mark must be performed more quickly than, for example, a database query
- the mark represents a context of the resource, such as in the context of an associated record