I am looking for a way to cache key -> value pairs on drive storage (not in memory, because it might go up to gigabytes), which could be groupped by tags.
For instance.
query1 -> data1 (tag1)
query2 -> data2 (tag1, tag2)
query3 -> data3 (tag2)
reset_cache(tag2)
Because the data are generated from a template, I would also need to check whether the template hasn’t changed whenever the cache is accessed.
I will appreciate any suggestion.
Try using an embedded database, for example H2. It will allow you to persist the data but since it’s embedded in your application, it doesn’t require setup, connecting to the server etc. The API is based around simple SQL, so if at some point your data grows and you need to use a real DB engine, it should be easy to move to MySQL, Postgres or whatever you will consider suitable at that time.
By creating a wrapper for put and get operations for use in your code, you will be able to perform additional operations, such as checking if the templates have changed, with each get.