简体   繁体   中英

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.

How do I programmatically invoke infinispan cache loader to load from *.dat file? I can parse the txt file and load the cache from it but not sure how to seed cache with dat file.

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; 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. 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. You could find an example how to instantiate it in 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. Objects are marshalled into bytes and back using VersionAwareMarshaller .

@Flavius is absolutely right. Cache Writers and Loaders are instantiated during startup.

You may consider implementing your own Custom Cache loader and deploying it on Hotrod server. The easiest way to do it is to use this archetype . Here you might find implementation details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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