Guava CacheBuilder only uses a single JVM. I want to use the CacheBuilder interface to load data from redis and redis in turn loads the data from MySQL.
How do I solve it? Is it even possible?
Why not try Spring Cache framework?It did good wrapper around Redis.
Related
I am using JCache with Redisson, it's not clear to me how serialization/deserialization works while using the cache.
When I setup the Cache via configuration I didn't setup anything about this. Is this done transparently?
The objects I am storing in cache are lists, objects from java.time for example, but I require all of objects of the classes I am storing in the cache implement Serializable, is this enough?
Looking at the data on redis it seems it is storing data serialized via java default serialization, am I wrong?
Can I control this behaviour? or it's better to leave it as it is ?
Thanks for help
As my comment, from redisson documentation Redisson use Kryo as default data serializer/deserializer.
I am new to Redis and planning to use it as in memory cache. I am using Lettuce 5.2 client for it.
I have multiple applications which will use redis as in memory cache. My idea is to write library using lettuce like wrapper which can be used by multiple application in order to interact with Redis. That library will manage connection pooling, redis failover cases and command execution etc. so that application writer should not worry about all this and just need to use my library.
Now for this library i am confused on below points :
1) Should i use Spring data redis (it also supports lettuce)? If my objective is to create library then first of all, can i use spring data redis ?
2) What all advantage Spring data redis will give me. I have checked documentation https://docs.spring.io/spring-data/data-redis/docs/current/reference/html/#reference
3) If i don't use Spring data redis then I will just use only lettuce and create client, connention pool etc myself.
I am confused whether i should use spring data redis for creating library or not ?
Can you please help me to clear my confusion ?
You are able to implement custom Repository methods in Spring Data, which has been outlined in other answers on SO such as here: How to add custom method to Spring Data JPA.
So you can easily combine both the out of the box Spring Data Redis functionality with custom Lettuce method code for a Spring Data Repository, I would suggest starting with Spring Data, and if you need to fine tune anything beyond that then write a custom methods with Lettuce.
So long as you can use the same connection pool in Lettuce as Spring Data Redis, you should be able to share that as a resource, the same way you can consider Threads as a resource.
No one can really give you a yes no answer as to what libraries you should or shouldn't use, hopefully you have enough information now to make progress going forward.
I have a search bar, and as soon as user types in he must be shown suggestions by querying the database. But if he tries to enter those same characters in sequence I want a way to cache the previous suggestions and return back to him without querying DB. I can use a hashmap but I need a much better implementation. I'm using hibernate as an ORM.
You can plug a cache into your ORM (I'd suggest EHCache, here's the corresponding manual section)
Or you can use a programmatic cache on the application layer. Here, I'd suggest a Guava Cache.
If you use Spring, then both of these are also available through Spring's own Cache abstraction
I'm trying to add to the current implementation of the app I'm working on a JCache compliant technology. At the moment, I've been able to use Apache Ignite and have it working with a couple of caches using an implementation of a cache store to read from and write to a database. The writes are done using write behind in batches. Some of the configuration is not part of JCache but I've been able to add it through the extended class of MutableConfiguration provided by Ignite. Also, I've done this using Spring without any CacheProvider or CacheManager so in my config class I expose the caches directly as beans. I get them from the Ignite class that accepts my configuration class and allows me to get the caches by name.
Now I'm trying to port this configuration to Hazelcast but I'm having problems doing it.
For starts, I haven't been able to find a way to configure the cache programmatically without an xml file. All examples I've found are using the the CacheManager that takes a Properties object with the path to this file. Would it work if I pass a path to a class instead of an xml?
I've seen that the Config.class used to configure a HazelcastInstance accepts a CacheSimpleConfig but then, HazelcastInstance doesn't have a getCache method or similar. If I configure the cache this way, how can I then get the cache from the HazelcastInstance?
Last thing, I've noticed there is no documentation related to configure write behind for a cache, only for maps. Is this not possible? Do caches only allow write through?
Thanks!
Since write-behind is not in the current JCache spec. it's also not in Hazelcast.
From Ignite's documentation,
"Ignite provides org.apache.ignite.cache.store.CacheStore interface which extends both, CacheLoader and CacheWriter."
This means you've to use Ignite's proprietary API to get write-behind functionality. IMHO using JCache is useless since you'll have a vendor lock-in in that case. Aim of JCache spec is to end all proprietary caching APIs.
If you'd like to use properietary APIs, then I'd recommend you to use Hazelcast's IMap to get write-behind functionality.
You can pass cache config programmatically while creating the cache;
Caching.getCachingProvider().getCacheManager().createCache("cache", cacheConfig);
Also below sample project can be useful;
https://github.com/hazelcast/hazelcast-code-samples/tree/master/hazelcast-integration/spring-jcache
It shows both XML and Java configuration.
I needed to implement a utility server that tracks few custom variables that will be sent from any other server. To track the variables, a key value collection, either JDK defined or custom needs to be used.
Here are few considerations -
Keeping all the variables in memory of the server all the time is memory intensive.
This server needs to be a very lightweight server and I do not want heavy database operations.
Is there a pre-defined streaming collection which can serialize the data after a threshold memory and retrieve it on need basis?
I hope I am clear in defining the problem statement.
Please suggest if any other better approach.
this thing looks very promising, but is in development stage...
JDBM3
Edit Current version of the file backed collections: MapDB.
Database
What you've described sounds exactly like you should use a database (i.e. indexed key/value store, too big for memory but want performance benefits of in-memory caching where possible).
I'd recommend a lightweight embedded database such as H2 - it's small, fast and should suit your purposes very well.
Have you thought of using an on the shelf nosql queue value store? Redis for example?
If you want it java only you have the option of using a lib like ehcache, it would have the functionalities you need.