cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Commerce: Cannot register custom manual cache region

2-15
Discoverer
0 Kudos

I'm quite new to the SAP Commerce development and want to create a manual cache region to cache data with custom logic. My extension contains the following snippet to define a EHCacheRegion and a CacheRegionRegistrar:

 

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:c="http://www.springframework.org/schema/c"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd">


    <bean name="fooCacheRegion" class="de.hybris.platform.regioncache.region.impl.EHCacheRegion">
        <constructor-arg name="name" value="fooCacheRegion"/>
        <constructor-arg name="maxEntries" value="50000"/>
        <constructor-arg name="evictionPolicy" value="LFU"/>
        <constructor-arg name="exclusiveComputation" value="false"/>
        <constructor-arg name="statsEnabled" value="true"/>
        <!-- 86400 = seconds per day (60 sec * 60 min * 24 h) -->
        <constructor-arg name="ttlSeconds" value="86400"/>
        <property name="handledTypes">
            <array>
            </array>
        </property>
    </bean>
    <bean id="fooCacheRegionRegistrar" class="de.hybris.platform.regioncache.region.CacheRegionRegistrar" c:region-ref="fooCacheRegion"/>
</beans>

 

 

This is based on https://help.sap.com/docs/SAP_COMMERCE/d0224eca81e249cb821f2cdf45a82ace/576988a1ca9e42e3a86877ab2c5b.... Except the CacheRegionRegistrar which was not even mentioned in the docs. (Thanks to https://community.sap.com/t5/customer-relationship-management-q-a/no-cache-region-displays-in-sap-cl... )

So far so good, but the custom cache region does not show up in the Hybris Admin Console under "Caches". With the following hack it shows up:

 

 

public Service(CacheConfiguration cacheConfiguration, EHCacheRegion fooCacheRegion) {
    // HACK manually register our cache region, so it is displayed in the HAC.
    // The "automatic" registration with our custom `CacheRegionRegistrar` does not seem to work.
    // The legacy approach as described in "core-cache.xml" with the `defaultScenarioCacheRegionList` does not work either.
    cacheConfiguration.getRegions().add(fooCacheRegion);
}

 

 

But the "Clear cache" button does not work at all for the cache because the DefaultCacheRegionProvider does not know about my cache region.

This looks totally wrong and I don't find the official documentation helpful at all. Can somebody point me in the right direction?

Accepted Solutions (1)

Accepted Solutions (1)

2-15
Discoverer
0 Kudos

I think I've got it right:

The manual cache region must be defined in a separate Spring XML file as a "global context" configuration:

<!-- resources/my-cache.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:c="http://www.springframework.org/schema/c"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd"
       default-lazy-init="true">
    <bean name="fooCacheRegion" class="de.hybris.platform.regioncache.region.impl.EHCacheRegion">
        <constructor-arg name="name" value="fooCacheRegion"/>
        <constructor-arg name="maxEntries" value="50000"/>
        <constructor-arg name="evictionPolicy" value="LFU"/>
        <property name="handledTypes">
            <!--
            This is a manual cache region, so we must not define handledTypes.
            Reference: https://help.sap.com/docs/SAP_COMMERCE/d0224eca81e249cb821f2cdf45a82ace/576988a1ca9e42e3a86877ab2c5bcc49.html?locale=en-US
            -->
            <array/>
        </property>
    </bean>
    <bean id="fooCacheRegionRegistrar" class="de.hybris.platform.regioncache.region.CacheRegionRegistrar" c:region-ref="fooCacheRegion"/>
</beans>

 This file must be referenced in the project.properties:

mymodule.global-context=my-cache.xml

 

Answers (0)