cache.capacities.com.mycompany.MyOuterClass.MyInnerCacheKey=100
CAE: Checking and Optimization of CacheKey Cache Efficiency
Learn about checking and optimization of CAE CacheKeys
What you will learn
- Knowing how to improve CAE cache efficiency
Prerequisites
- Blueprint Workspace
- CAE knowledge
Target Audience
Checking Cache Efficiency
It is strongly recommended to check your project’s individual cache capacity settings before launching a new or overhauled
site as soon as a reasonable amount of production-like data is available. The same holds when upgrading to a newer release
of the CoreMedia Blueprint. Ideally, compare eviction rates of the current system with the upgraded system. Preferably, use
a load test which processes the majority of your sites' data. Check for eviction rates in all cache classes. None should
be increased. Also check for changes in Java heap memory consumption and GC timings. Neither should be increased. Adjust
cache capacities and/or Java maximum heap accordingly, if necessary. Ideally, use a monitoring tool to gain insights. Alternatively,
you can retrieve the information via CAE actuator endpoint/actuator/prometheus. The following entries in the delivered
metrics are relevant for an investigation:
-
coremedia_cache_evictions_total{class="<cache-class>"}: number of evictions in cache class<cache-class>due to exceeded cache capacity. -
coremedia_cache_gets_total{class="<cache-class>"}: number of read accesses in cache class<cache-class>. This should be much larger than the number of evictions in that class. -
coremedia_cache_evaluation_duration_seconds{class="<cache-class>"}: time to compute an item in cache class<cache-class>. This can help in estimating optimization potential if the number of evictions in that class is considered too high. -
coremedia_cache_level{class="com.coremedia.cap.heap"}: estimated memory consumption of elements in cache classcom.coremedia.cap.heap. -
jvm_gc_overhead: approximation of the percent of CPU time used by GC activities. -
jvm_memory_used_bytes{area="heap",id="<heap-space>"}: amount of used Java heap memory different heap spaces.
Introducing Individual Cache Classes
With releases 2512.0.2, 2506.0.4, 2406.3.2, and 2406.2.3, a new mechanism to dynamically look up cache classes is introduced. If you are working on an older release, the following section does not apply. Separation of cache keys into dedicated cache classes can then only be done via overwriting method CacheKey#cacheClass(Cache, T) in your projects' cache keys.
If no specific cache class is defined in a cache key implementation via CacheKey#cacheClass(Cache, T),
lookup of a cache class for this cache key is done by traversing the type hierarchy against the configured capacities of
a cache. See the Java documentation for CacheKey#cacheClass(Cache, T)
and Cache#cacheClassFor(Class<?>).
This mechanism can be employed if cache keys predefined by the product or defined in your project should be pulled from
default cache class java.lang.Object into a dedicated cache class. This way, cache optimization can be performed without
changing cache class definition in the code of the cache key implementations.
Example
To define a dedicated cache class for cache key com.mycompany.MyOuterClass$MyInnerCacheKey, add the following
line (with appropriate capacity for your project) to the Spring configuration of your CAEs:
However, it is not strictly necessary to move cache keys from default cache class java.lang.Object into a dedicated cache
class unless one of the following occurs:
-
A high eviction rate is observed and the cache capacity cannot be increased or
-
The cache requires too much Java heap occasionally and the heap cannot be enlarged.
In those cases, introducing dedicated cache classes will give you better control over eviction rate and heap consumption.
Use the actuator endpoint /actuator/cache/java.lang.Object?keys=true of a CAE to get information about cache keys that are
stored in the default cache class.
Consider requesting support from CoreMedia Customer Success when in doubt regarding the procedure of checking and optimizing cache settings.