简体   繁体   English

使用@Cacheable Spring批注并手动添加到Infinispan Cache

[英]Using @Cacheable Spring annotation and manually add to Infinispan Cache

I am trying to load my cache off of a cold start, prior to application startup. 我正在尝试在应用程序启动之前从冷启动加载缓存。 This would be done so values are available as soon as a user accesses a server, rather than having to hit my database. 这样做是为了使用户在访问服务器后就可以使用值,而不必访问我的数据库。

@Cacheable functionality from Spring all works great, the problem is how I manually store objects in the Cache so that they can be read when the function is executed. Spring的@Cacheable功能都很好用,问题是我如何在Cache中手动存储对象,以便在执行函数时可以读取它们。

Spring is storing these objects in bytes, somehow -- and I need to mimic this while I manually load the cache. Spring会以某种方式将这些对象存储在字节中,而在手动加载缓存时,我需要模仿这些对象。 I'm just trying to figure out how they process the return objects, in the function, to store into the cache in a key,val pair. 我只是想弄清楚它们如何处理函数中的返回对象,以键,值对的形式存储到缓存中。

You can programmatically access any cache by using Spring's CacheManager . 您可以使用Spring的CacheManager以编程方式访问任何缓存。

See https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/cache/CacheManager.html 参见https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/cache/CacheManager.html

var cache = cacheManager.getCache("foo");

cache.put(key, value);

I was able to solve this problem by storing values as a string key and object value -- which works wonderfully with Spring @Cacheable annotations. 我能够通过将值存储为字符串键和对象值来解决此问题-与Spring @Cacheable批注完美配合。 Objects are casted into the return types by Spring if they are found within the cache. 如果对象在缓存中找到,则对象将由Spring强制转换为返回类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Infinispan中将可缓存注释与树缓存一起使用 - Using Cacheable annotation with treecache in Infinispan Spring Framework + Hazelcast,如何使用@Cacheable注释启用/禁用缓存 - Spring framework + Hazelcast , how to enable/disable cache using @Cacheable annotation Spring 缓存特定值@Cacheable注解 - Spring cache for specific values @Cacheable annotation 修改@Cacheable spring 注解以使用二级缓存管理器将值写入缓存 - Modify @Cacheable spring annotation to use a secondary cacheManager for writing values to cache Spring Boot 中的可缓存注解 - Cacheable Annotation in Spring Boot Spring 中@Cacheable 注释的编程替代方案 - Programmatic alternative to @Cacheable annotation in Spring 使用 org.springframework.cache.annotation.Cacheable 时从缓存中删除项目的超时时间是多少 - What is the timeout for items getting removed from cache when using org.springframework.cache.annotation.Cacheable Spring @Cacheable注解用于不同服务中的相同方法 - Spring @Cacheable annotation for same method in different service Spring Boot EnableCaching和Cacheable注释无效 - Spring Boot EnableCaching and Cacheable annotation not working Spring - @Cacheable 注释不适用于 java 方法 - Spring - @Cacheable annotation not working on java method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM