[英]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.