Feeds as cache invalidation mechanism
By traviscj
- One minute read - 120 wordsOne really cool use of feeds we’ve realized is that it gives a very efficient mechanism for application code to load the most recent versions of a table into memory. The basic idea is:
- Set it up as a usual feed published table with an appropriate index on
feed_sync_id
. - Either alongside or within the cache, represent the latest loaded
feed_sync_id
. - Set up a cronjob/etc that reads the latest
feed_sync_id
and compares it to the cache’sfeed_sync_id
. - If they differ, reload the cache.
- Ensure that all changes set
feed_sync_id
to null!
This works really well because the feed_sync_id
in the database only gets updated on changes, so the reload cronjob mostly is a no-op.
This means we can reload very frequently!