Reputation: 2999
I am trying to implement a cache with a prefetch functionality.
The plan is that if the cache entry is new, then it will be returned as is. If the cache is older than a set age then the "old" cache will be returned while a new thread is spawned to refresh the entry. If it is even older than that it will update the entry and then return it.
The plan with this is to avoid having a cache miss where the user needs to wait for the cache to be refreshed.
I have sort of gotten a working model using a hashmap as a cache store, but this seems kind of dirty.
So I want to use the javax.cache.cache-api
package for this and I chose org.infinispan.infinispan.jcache
as an implementation.
The problem is that the objects I want to save in the cache is not serializable and I can't figure out how to make inifinispan allow them.
The reason for why they aren't serializable is because they store the functions to also update the cache entry.
Question is: Can you store non serializable objects like this with infinispan and if so, how?
Or is there any out of the box solution that already does what I am after?
Upvotes: 2
Views: 3088
Reputation: 6107
Infinispan doesn't require your values to be Serializable
.
This is only needed for clustered caches, but for your use case looks like a reasonable local-only Cache could be better suited.
Obviously if you need the caches to replicate data across servers and/or data centers, then Infinispan will need some way to marshall your objects across wires. If you want to use those features too, you can plug in custom Externalizer
implementations for your types.
Plugging in custom Externalizer implementations is possibly a good idea even for your Serializable types, as the custom Externalizer framework will typically perform better than Java's standard serialization.
Upvotes: 4
Reputation: 1272
Since Infinispan 5.0, marshalling non-Serializable key/value objects is supported as long as users can provide meaningful Externalizer implementations for these non-Seralizable objects. This section has more details.
Upvotes: 1