3 ms·
What exactly are you trying to solve/fix? If you want to improve performance in an application, structure it in a way that lets you cache the result set in-mem
by gt565k 5y ago
What exactly are you trying to solve/fix?
If you want to improve performance in an application, structure it in a way that lets you cache the result set in-memory at the app layer. Assuming the only way to update data is through the same app, refresh/rehydrate the related cache when records are updated/deleted/inserted. You'll only hit the database the first time, and then again when the cache is cleared in your app layer logic.
This is more or less how Active Record ORM caching in Rails works.
You gotta key off of something so it is very application specific but lets take your example a step further.
The items and list are for a specific user. Whenever an item gets added to a list or a list gets added to an item, nuke the cache key for 'user/$ID/list_items' or whatever you want to call it. Whenever you read, you hit the same cache key in-memory, so your reads are always avoiding a database roundtrip. You can do the same logic for deletes/updates, etc... and structure based on the hierarchy of your data or your tree dependency of records