Home


2.8 Invalidation: Getting stale objects out of the cache

A second, critical invalidation policy defines when to evict cache items. The strategy for removing expired cache entries is an essential part of cache design. Cache entries might:

Expire after a given amount of time

Be removed from the cache based on dependency rules

Be removed on the basis of a Least Recently Used algorithm when the cache needs space for new entries

The operation of removing entries from the cache is called invalidation. The easiest method for cache invalidation is to set a time-to-live (TTL) value on the cache entry, though we do not encourage this, as we explain later in the invalidation best practices section.

Wherever possible, you should create an explicit invalidation policy for each cache entry in the cachespec.xml file. This policy defines an invalidation rule very similar to the cache ID rule, and an invalidation ID is generated based on that rule. When an invalidation rule is specified for an object, DynaCache generates an invalidation ID during the execution of that object and checks it against the cache IDs of all entries currently in the cache. If a cache ID matching the invalidation ID is found in the cache, the cache entry associated with this cache ID is removed from the cache (meaning it is invalidated).

DynaCache also provides a group-based invalidation mechanism based on dependency lDs. A dependency ID defines a cache entry's dependency rule. Different objects, based on their defined rules, might generate the same dependency ID. If an invalidation ID is generated for a request that matches a given dependency ID, all the cache entries associated with that dependency ID are removed from cache.

The invalidation ID is generated by concatenating the invalidation ID base string with the values returned by its component element. If a required component returns a null value, then the entire invalidation ID is not generated and no invalidation occurs. Multiple invalidation rules can exist per cache-entry. All invalidation rules run separately.

We encourage defining invalidation rules to automate the invalidation of cache entries. If you do not have invalidation rules configured, then invalidate the entire cache when content changes. This means that everything is removed from the cache, and not just the changed pages. The invalidation of the complete cache is not recommended and should be avoided whenever possible since it leads to a poor user experience.

+

Search Tips   |   Advanced Search