The SpEL Resolve Method Results Cache
Results from the SpEL resolve method change infrequently. Data Hub therefore supports caching of resolve method results, offering potentially significant performance improvements.
Data Hub has support for SpEL expressions in the extension.xml file. This support allows you to define rules for transforming one item type to another. The Data Hub implementation of SpEL includes the resolve method, which resolves references to other items and their attributes. Data Hub evaluates a resolve expression multiple times with the same result under certain conditions, and in certain processing phases.
Resolve method caching is based on the Spring caching abstraction, which allows method-level annotations to trigger the checking, population, and clearing of the cache. EhCache is used as the foundation for the cache itself. The cache adds items when a lookup happens for the first time, and is cleared at the end of each composition or publication action.
All cache operations are specified by annotations, and operate on a cache named spelResolveCache. Default properties for this cache are provided in the following table. Any properties that are not specified here are inherited from the ehcache.xml config file in the classpath. The location of this default file can be changed using the property datahub.caching.configuration.resource.name in your local.properties file.
| Property name | default value | Description |
|---|---|---|
| datahub.caching.spelResolveCache.maxEntriesLocalHeap | 100000 | The maximum number of entries the cache can keep in memory. The cache evicts elements once the limit is reached. See the eviction policy described later. |
| datahub.caching.spelResolveCache.timeToIdleSeconds | 600 | The maximum number of seconds an element can exist in the cache without being accessed. The element expires at this limit and is no longer returned from the cache. |
| datahub.caching.spelResolveCache.timeToLiveSeconds | 600 | The maximum number of seconds an element can exist in the cache regardless of use. The element expires at this limit and is no longer returned from the cache. |
| datahub.caching.spelResolveCache.evictionPolicy | LFU | The policy to use in cases when items are evicted from the cache. Available policies are: Least Recently Used (LRU), Least Frequently Used (LFU), First In First Out (FIFO) configuration |
Extending the Resolve Method Cache Configuration
It is possible to override the provided resolve method caching functionality. The override is useful in cases where the default configuration properties provide insufficient control over the caching functionality for your needs.
Context
You extend the resolve caching functionality by overriding the EhCacheFactoryBean with ID spelResolveCache. When overriding the existing EhCacheFactoryBean, be sure to reuse the cacheName spelResolveCache. The Data Hub code references this cacheName in all caching annotations.
You can set all available properties of the org.springframework.cache.ehcache.EhCacheFactoryBean when overriding. One particular interesting property is cacheManager, which references a bean of type EhCacheCacheManager. This bean can point to a redefined EhCacheManagerFactoryBean, which points to a newly generated ehcache.xml config file. Instructions for configuring this file can be found in the EhCache Documentation
Procedure
Extending Caching to Other Custom SpEL Methods
You can implement caching for your own custom SpEL methods that use a MethodResolver and MethodExecutor. This implementation is done in the same way as extending the resolve method.