Java cache as database?

910 views Asked by At

How are java cache libraries usable as database?

My I use something like Ehcache or JCS instead of database?

Is it true that Ehcache supports persistence strategy = localRestartable only for Enterprise Ehcache, i.e. paid version?

Does it mean free version does not suitable for database replacement?

UPDATE

Why isn't persistent cache a database replacement? What is the principal difference between database engine operation and cache operation with dist storage?

Here is an example of comparison between neo4j (graph database) and Ehcache (cache): http://vschart.com/compare/ehcache/vs/neo4j-community They appear comparable.

1

There are 1 answers

0
Louis Jacomet On

A cache is an application component that trades increased memory use for lower latency in data access. It usually has a concept of eviction coupled with the postulate that it holds data which can be queried from elsewhere or reconstructed.

These two concepts combined allow cache implementors to drop an entry from the cache at any time they see fit, for limiting cache resource utilisation, to favour entries that have a more frequent access pattern or simply to not have the cache be a source of increased latency.

This is the main reason why a cache should not be used as a datastore.

Now some cache implementations may offer feature to prevent eviction, but in that case you end up paying the price of the eviction logic/complexity which would not be present in a datastore.

Regarding Ehcache persistence, the legacy mode overflowToDisk=true and diskPersistent=true offer a limited "survive the JVM restart" persistence. It is however very sensitive to proper shutdown and upon detecting any corruption on startup, the cache will discard all contents and restart empty. See above for why this is a valid option in the context of a cache.