We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

modelsCache cache invalidation

I'm currently working on optimizing our high-performance platform, and i do want to implement modelsCache, to cache resultsets... But i can't find a good way to cache & invalidate modelsCache dynamically?

What is the best way to cache & invalidate modelsCache service? Store unique keys some place and in afterUpdate/afterDelete invalidate cache manually?

Thank you



145.0k
Accepted
answer

Yea i guess, phalcon doesn't really have built-in mechanism for this. Though cache invalidation will always be hard, what if you for example use joins etc and you update only one model? Then you need to clean it too for joins etc.

You possibly could get more interested about varnish.

edited Sep '18

Yeah, my intention was to only cache findFirst/find functions... With joins it gets way too complicated... But really it seems like a half solution hm....

Not really sure Varnish could solve the problem... Api changes frequently :)