Is there a way to issue a postgres update query that just does nothing if the row it wants to update is locked? Or perhaps waits a very short time before giving up, just for this query?
I have a table with an updated_at field which is used for Russian doll caching. Russian doll caching basically uses updated_at data in cache keys so you can invalid the cache by simply modifying the updated_at field. So for example if you have 2 tables:
You can now cache a book based on books.id and books.updated_at. If a page changes you change the updated_at for the parent book and that book's cache is invalidated.
The issue is if a large number of pages for the same book are being modified at the same time, you end up with a flood of queries to update updated_at for the same book record. As result, there is a ton of blocking while each update queries waits for a lock. We actually don't need all the updates to happen since it is just being used to invalid that cache. So if only one actual update happens per sec we are fine.
Any thoughts on how to achieve this?