0

I am using the @Cacheable("MyCache") annotation along with the PCC (Pivotal Cloud Cache) provider.

Here is my configuration class

@Configuration
@EnableCachingDefinedRegions
@EnableClusterAware
public class CachingConfig {
}

I see that there is a @Expiration annotation available but it is recommended with @EntityDefinedRegions. Need help with configuring the expiration policy using the @EnableCachingDefinedRegions

1 Answers1

0

Previously, SDG did not support annotation-based expiration configuration (i.e. using @EnableExpiration) with @EnableCachingDefinedRegions due to the way the infrastructure beans were created and registered in the Spring container.

However, I decided (see Issue #518) to make some enhancements to the annotation-based configuration model to enable expiration configuration using @EnableExpiration on Regions defined with @EnableCachingDefinedRegions.

By way of example, refer to this test case in the EnableExpirationConfigurationIntegrationTests class of the SDG test suite. The caching/expiration configuration you are looking for is here along with the caching enabled application service class.

Since you are also using SBDG (which is good(!)), then you can simplify the configuration to:

@SpringBootApplication
@EnableClusterAware
@EnableCachingDefinedRegions
@EnableExpiration
public class MySpringBootApacheGeodeApplication { 
    ...
}

By default, the SDG @EnableExpiration annotation applies to all Regions. However, you can configure the expiration policy per [caching-based] Region using the policies attribute on the @EnableExpiration annotation.

Refer to the SDG Reference Documentation for more details.

These changes will be part of the releases coming up this week. Specifically, these changes will be part of SDG 2.5.3 and SDG 2.6.0-M1. I did not back port these changes to SDG 1.4.x. The releases go out on Friday, July 16th.

John Blum
  • 7,381
  • 1
  • 20
  • 30
  • Thank you very much for the response:-) I used another approach where the Expiration started working by enabling Region annotation and EnableEntityDefinedRegions. So on my Region definition, I have used TimeToLiveExpiration annotation. That works effectively with the EnableExpiration annotation. Now when I push changes to the CloudFoundry environment with PCC, I get the following exception : java.lang.IllegalStateException: if the data policy is empty then entry expiration is not allowed. Please help with configuring Region Data Policy. I couldn't find any documentation. – Sandip Singh Jul 15 '21 at 12:36
  • The exception is solved. Actually I was falling back to default clientRegionShortcut on the EnableEntityDefinedCacheRegions annotations which are PROXY by default. In the GemfireCache class while intialising the Regions it was setting the DataPolicy to EMPTY when the ClientRegionShortcut.PROXY is used. My intention was to use a Client Cache anyways, so I changed it to ClientRegionShortcut.CACHING_PROXY. This solved my problem while deploying the application to PCC as well :) – Sandip Singh Jul 15 '21 at 13:14