IObjectInstanceCache` and `
ISynchronizedObjectInstanceCache` interfaces expose the built-in cache system with custom dependency and eviction policies.
Optimizely Content Management System (CMS) and Optimizely Customized Commerce use these interfaces to cache both content and system data, and you can use the interfaces to cache custom data. The `
ISynchronizedObjectInstanceCache` interface synchronizes cache removal among servers in a load-balanced environment using the [Event management](🔗) system.
If you were using the `
CacheManager` class in CMS, you should take a dependency on `
ISynchronizedObjectInstanceCache` instead, because the new interface provides the same functionality. The `
IObjectInstanceCache` supersedes `
IRuntimeCache` (that was previously used only by CMS) because it supports different cache implementations by abstracting the `
CacheDependency` class and other things.
Use the `
CacheEvictionPolicy` class for object caching, because it is de-coupled from any specific cache implementation. `
CacheEvictionPolicy` is immutable so you can re-use existing instances of the class. (The `
CacheDependency` class is tightly coupled to the `
HttpRuntime` implementation and if you want to have a custom cache implementation you cannot rely on `
CacheDependency`.) The following example shows how to use `
## Master keys
When you need to define a common dependency for cached data, create a master dependency (or master key) with `
CacheEvictionPolicy`, which automatically adds a list of key names to the cache as regular cache entries. By doing so, you do not need to add code to conditionally add these entries before you insert specific data into the cache.
In the following example, the difference between the cache key dependency and the master key dependency is that if there is no `
otherKey` in the cache then the data is not inserted. If there is no entry with `
MasterKey`, then it adds a dummy value with the given key, thus allowing the data to be inserted successfully.