• Products
  • Solutions
  • Customers
  • Resources
  • Company
  • Pricing
  • Download
Try Playground
Show / Hide Table of Contents

Configure JCache Spring Cache Provider

Spring 6.0.12 supports JCache-compliant caching providers. You can also use JCache caching backed by NCache if your Spring version supports JCache. Simply modify the configuration by following the steps below and use Spring seamlessly with the NCache JCache Spring Caching Provider.

Prerequisites to Configure JCache Spring Cache Provider

  • To learn about the supported Java versions, please refer to the NCache Installation Guide.
  • To configure the Spring Cache Provider ensure that following prerequisites are fulfilled.

    • Add spring-context-support dependency for configuring Spring Framework.
    • Add spring-boot-starter-cache dependency for configuring Spring Boot.

Add Maven Packages

The user needs to add the following Maven dependencies in their pom.xml file while configuring JCache Spring Cache provider.

<dependency>
    <groupId>com.alachisoft.ncache</groupId>
    <!--for NCache Enterprise-->
    <artifactId>ncache-client</artifactId>
    <!--for NCache Professional-->
    <!--artifactId>ncache-professional-client</artifactId-->
    <version>x.x.x</version>
</dependency>
Note

To use Maven packages for the NCache Professional, change the <artifactId> as <artifactId>ncache-professional-client</artifactId>.

Defining Cache Configurations

Note

To enable caching in the Spring application, add the @EnableCaching annotation.

JCache is bootstrapped through the javax.cache.spi.CachingProvider, a JSR-107 compliant caching library on the classpath.

If you have more than one provider of JCache in your .classpath, then the tags spring.cache.jcache.provider and spring.cache.type needs to be explicitly added in the application.properties file.

spring.cache.jcache.provider=com.alachisoft.ncache.jsr107.spi.NCacheCachingProvider
spring.cache.type=jcache

Configure Caches

Note

To initialize multiple caches on application startup, provide a spring.cache.cache-names tag with comma-separated cache names.

To configure your cache for the JCache Spring application and to initialize your cache at the application startup, you need to add the spring.cache.cache-names tag in the application.properties file. The cache name should be the same as configured in the NCache Management Center.

spring.cache.cache-names=demoCache,booksCache

Also, you can edit the JCacheManagerCustomizer class to configure the JCache spring cache and initialize it with those configurations at runtime.

@Configuration
public class CacheConfiguration implements JCacheManagerCustomizer
{
    @Override
    public void customize(CacheManager cacheManager)
    {
        MutableConfiguration mutableConfiguration = new MutableConfiguration();
        mutableConfiguration.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(Duration.ONE_MINUTE));
        cacheManager.createCache("booksCache", mutableConfiguration);
    }
}

Once you have enabled caching, bind the caching behavior to the methods to use NCache as a Caching Provider for Spring. To do so, refer to section Configure Applications using Caching Declaration.

See Also

Configure Application for Generic Spring Caching Provider
NCache as Spring Data Cache

In This Article
  • Prerequisites to Configure JCache Spring Cache Provider
  • Add Maven Packages
  • Defining Cache Configurations
    • Configure Caches
  • See Also

Contact Us

PHONE

+1 (214) 764-6933   (US)

+44 20 7993 8327   (UK)

 
EMAIL

sales@alachisoft.com

support@alachisoft.com

NCache
  • NCache Enterprise
  • NCache Professional
  • Edition Comparison
  • NCache Architecture
  • Benchmarks
Download
Pricing
Try Playground

Deployments
  • Cloud (SaaS & Software)
  • On-Premises
  • Kubernetes
  • Docker
Technical Use Cases
  • ASP.NET Sessions
  • ASP.NET Core Sessions
  • Pub/Sub Messaging
  • Real-Time ASP.NET SignalR
  • Internet of Things (IoT)
  • NoSQL Database
  • Stream Processing
  • Microservices
Resources
  • Magazine Articles
  • Third-Party Articles
  • Articles
  • Videos
  • Whitepapers
  • Shows
  • Talks
  • Blogs
  • Docs
Customer Case Studies
  • Testimonials
  • Customers
Support
  • Schedule a Demo
  • Forum (Google Groups)
  • Tips
Company
  • Leadership
  • Partners
  • News
  • Events
  • Careers
Contact Us

  • EnglishChinese (Simplified)FrenchGermanItalianJapaneseKoreanPortugueseSpanish

  • Contact Us
  •  
  • Sitemap
  •  
  • Terms of Use
  •  
  • Privacy Policy
© Copyright Alachisoft 2002 - 2025. All rights reserved. NCache is a registered trademark of Diyatech Corp.
Back to top