Hacker News new | ask | show | jobs
by TheCloudlessSky 4823 days ago
I'm curious: how does Shopify handle database migrations with the cached models? Do you explicitly invalidate the caches when a migration is run?

The reason I ask is because in the .NET/NHibernate world, this is akin to a 2nd level cache provider. I maintain a Redis caching provider for NHibernate (https://github.com/TheCloudlessSky/NHibernate.Caches.Redis) and I've been trying to find a decent solution to this problem. When NHibernate fetches a cached model with mismatching columns etc, it'll blows up with an exception.

I like the generational approach that is part of Rails 4 but it really only works for the views. Maybe incorporating some sort of generational identity of the model's configuration could be used for cache busting?

1 comments

The way schema migrations are handled is by making a hash of the current schema part of the cache key, so yeah, effectively every time a cached model's underlying table schema is changed all the cached entries become invalid.