0

I'm just started out with Ehcache, and it seems pretty good so far. I'm using it in a simplistic fashion to speed up reads against a database, but I wonder whether I can also use it to let the application stay up if the database is unavailable for short periods. (Update - my context is a application with high-availability modules that only read from the database)

It seems like I could do that by disabling expiry in the event of a database read problem, and re-enabling it when a read works again.

What do you think? Is that a reasonable approach or have I missed something? If it's a fair approach, any tips for how best to implement appreciated.

Update - ehcache supports a dynamically configurable option to un/set the cache to 'eternal'. This seems to do what I need.

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
brabster
  • 42,504
  • 27
  • 146
  • 186

1 Answers1

1

Interesting question - usually, the answer would be "it depends".

Firstly, if you have database reliability problems, I'd invest time and energy in fixing them, rather than applying a bandaid solution.

Secondly, most applications need both reading and writing to work - it doesn't seem to make sense to keep your app up for reads only.

However, if your app has a genuine "read only" function, and there's a known and controlled reason for database down time (e.g. backups), then yes, you can use your cache to keep the application up and running while the database is down. I would do this by extending the cache periods, rather than trying to code specific edge cases. For instance, you might have a background process which checks whether the database is available and swaps in a different configuration file when there's trouble.

Neville Kuyt
  • 29,247
  • 1
  • 37
  • 52
  • Yep, I'm in that category you describe. Thanks for pointing out the additional considerations for applicability. – brabster Aug 12 '11 at 10:30
  • In addition, I've found that ehcache has the option of dyamically switching on/off 'eternal' which seems to do exactly what I need. – brabster Aug 12 '11 at 10:31