Hi there.
With one of our recent projects we have a requirement to cache a single object in the web server.
This object is refreshed from the database at regular intervals. Also, the object is read-only. Not in the true sense of the word (with Object.freeze, getters etc.) but in the sense that our application doesn't need to change it. Finally, refreshing the cached object has the potential to return no results, in which case the requirements are to bring the application offline by returning a 500 - Offline type page.
We saw this as a good opportunity to utilise catbox to save ourselves the hassle of cache management. catbox-memory looked perfect for our needs.
All went well until we looked into performance testing and found that the stringify/parse overhead was having quite an impact. Mainly due to the size but also due to the number of times we access it (on every prehandler
).
We soon realised what was going on and that to protect against mutating objects in the cache, catbox-memory saves a copy of the object and deserializes it on the way out. We also realized that this is good thing in it works in a consistent way to other adapters that are not in-memory (e.g. redis).
The problem is that we don't have those requirements and we just want to store the object in the cache as-is, aware of the consequences that this may bring in terms of state/mutations. We don't want to write our own cache management or use another package as we'd rather stay in the hapi ecosystem.
We are toying with the idea of writing our own catbox adapter ("catbox-object" maybe?) that is virtually the same as this but without the serialization and with a big WARNING about state/mutating objects in cache.
I wanted to run this past you first to see if you had any suggestions or to see if you thoughts.
Many thanks
Dave