0

I want to run a java function and it generates a json that has about 1M size. I need the json for input of next call that is 2 minute later. I can save the json in a database, but the time is spent on saving in database is not acceptable for me. can I keep this data in memory and use for next call? I need also read this data from node.js. how can I do this job?

2
  • you can use lru-cache in node and set expiration. npmjs.com/package/lru-cache Commented Jul 9, 2016 at 12:23
  • dear @fullOfQuestions, kindly accept one of the answers Commented Jul 14, 2016 at 19:32

2 Answers 2

2

Why dont you use a persistent asynchronous queue in between you application and your database. This way you will just fire and forget the persist operation and serve the result as fast as possible.

If you want to also keep the object in memory your best bet would be something like Infinispan or Hazelcast. Infinispan offers it own persistent store for the cache and good database integration. Hazelcast on the other end works more as In memory key value store but some persistence can easily be implemented with it as well. Hazel cast is very easy to start with and the learning curve is not that steep.

The good thing about this infrastructure is that you can have safety that your data is in sync with database. For example you can configure how many backups of particular object to be kept and these backups are created asynchronously or synchronously depending on how you configure them. You can also send the data to the database. If persistence is strong requirement probably Infinispan is better in this regards.

When I was reading second time your post I realized that maybe you need something significantly simpler when it comes to caching. If you just need a local cache with no backup capabilities, just go for EHCache.

Sign up to request clarification or add additional context in comments.

Comments

1

hazelcast is a Java library that provides API's to solve caching use case. It extends java collections with capabilities suitable for caching use case - eviction, ttl for entries, read through and write through cache, etc.

For node.js use case please find my answer here https://stackoverflow.com/a/36704734/27563

Let me know if you have any questions.

Thanks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.