artsy/garner

Caching the Index method

AndreiDev opened this issue · 2 comments

Hi!
In my Orders controller, there's an index method that returns all orders for a specific account.
Is there a way to cache calls like current_account.orders (get all orders that the current_account has), invalidating only when the number of orders for current_account changes?
Thanks!

You could construct a key manually that is a combination of current account ID and, say, "orders", then invalidate that cache entry whenever an order affects an account. Garner doesn't help that much here otherwise.

If you create an Order without touching the account record at all, then you'd have to bind on any order, including when someone else's account changes. I suggest touching the current_account and then just doing garner.bind(current_account) and calling it a day.

I'll close this, let us know whether you have more questions!