I want to cache objects in memory. The requirements are as follows:
- Every record/object is associated with a unique key.
- 400-500 records/objects to be stored. If the number of records increase beyond the specified limit, then the older records should be evicted.
- Records shouldn't be stored beyond 2 mins.
- Should scale down when JVM is running out of memory (kind of weak reference).
- Third party library cannot be used because its a small module and the intention is just to decrease the unnecessary network access.
- There are more writes, less reads
Security is also a concern here because we are going to cache some sensitive data. This data will be cached in memory. Should I really worry about the security and encrypt the data?
I am looking for a Java class which provides a similar functionality.
Currently I am thinking of extending WeakHashMap
, and implementing various private/public methods to adhere to the requirements.
If you have any other idea please share here.