Search code examples
cachingehcachesap-commerce-cloud

How to create a new cache region in SAP Commerce (hybris)


I need to create a new region for a specific set of models. I've followed the documentation about RegionCache but it doesn't work.

Here is the configuration :

<alias name="defaultTestCacheRegion" alias="testCacheRegion"/>
<bean name="defaultTestCacheRegion" class="de.hybris.platform.regioncache.region.impl.EHCacheRegion">
    <constructor-arg name="name" value="testCacheRegion" />
    <constructor-arg name="maxEntries" value="${regioncache.testcacheregion.maxentries}" />
    <constructor-arg name="evictionPolicy" value="${regioncache.testcacheregion.evictionpolicy}" />
    <constructor-arg name="statsEnabled" value="${regioncache.stats.enabled}" />
    <constructor-arg name="exclusiveComputation" value="${regioncache.exclusivecomputation}" />
    <property name="handledTypes">
        <array>
            <value>25049</value>
            <value>25050</value>
            <value>25051</value>
        </array>
    </property>
</bean>
<bean id="testCacheRegionRegistrar" class="de.hybris.platform.regioncache.region.CacheRegionRegistrar" c:region-ref="testCacheRegion" />

Solution

  • I actually miss how the Spring context works in hybris. Since it has to be accessible from all application contexts it has to be set on global level.

    All application contexts have as the parent the global application context.

    The cache region bean has to be defined in a "global" spring file. In hybris it's done by setting this property. (my_cache.xml has to be in resources in project_name)

    <project_name>.global-context=my_cache.xml