简体   繁体   English

如何以编程方式调用infinispan缓存加载器

[英]how to programmatically invoke infinispan cache loader

I want to setup a cache loading strategy such that the infinispan cache is seeded with content from either the *.dat (the one created by infinispan itself) or a human readable txt file (created by manually exporting cache entries) based on a system property. 我想设置一个缓存加载策略,以使infinispan缓存中的内容来自* .dat(由infinispan本身创建的)或基于系统属性的人类可读的txt文件(由手动导出缓存项创建的) 。

How do I programmatically invoke infinispan cache loader to load from *.dat file? 如何以编程方式调用infinispan缓存加载器以从* .dat文件加载? I can parse the txt file and load the cache from it but not sure how to seed cache with dat file. 我可以解析txt文件并从中加载缓存,但不确定如何使用dat文件播种缓存。

Cache loaders/writers are created on startup, there's no way how to add it on the fly. 缓存加载器/写入器是在启动时创建的,因此无法即时添加。 However, you can: 但是,您可以:

a) Create new cache and put the cache loader into programmatic configuration; a)创建新的缓存并将缓存加载器置于程序配置中; then you'd just call cache.entrySet() or even better cache.getAdvancedCache().filterEntries() and read the cache contents including data in the store, and feed them to the target cache. 那么您只需调用cache.entrySet()甚至更好的cache.getAdvancedCache().filterEntries()并读取包含存储中数据的缓存内容,并将其提供给目标缓存。 You should probably clear the cache in some way during the loading, so that you don't run off memory when the file is too large. 您可能应该在加载过程中以某种方式清除缓存,以便在文件太大时不会耗尽内存。

b) Create just the cache loader class itself ( SingleFileStore ) and call process() to read all entries. b)仅创建缓存加载器类本身( SingleFileStore ),然后调用process()读取所有条目。 You could find an example how to instantiate it in testsuite. 您可以找到一个在testsuite中实例化它的示例。

c) Look into the code to see the format - it's actually quite simple, 4 magic bytes on the beginning of the file, entry size (4 bytes), key length (4 bytes), data length (4 bytes), metadata length (4 bytes) and expiration timestamp (8 bytes) in the header, followed by key, data and metadata. c)查看代码以查看格式-实际上很简单,文件开头有4个魔术字节,条目大小(4个字节),键长(4个字节),数据长度(4个字节),元数据长度(标头中包含4个字节)和到期时间戳记(8个字节),然后是密钥,数据和元数据。 Objects are marshalled into bytes and back using VersionAwareMarshaller . 使用VersionAwareMarshaller对象编组为字节并返回。

@Flavius is absolutely right. @Flavius绝对正确。 Cache Writers and Loaders are instantiated during startup. 高速缓存编写器和加载器在启动期间实例化。

You may consider implementing your own Custom Cache loader and deploying it on Hotrod server. 您可以考虑实现自己的Custom Cache loader并将其部署在Hotrod服务器上。 The easiest way to do it is to use this archetype . 最简单的方法是使用此原型 Here you might find implementation details. 在这里您可以找到实施细节。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM