I have a database class, which manages all my mysql connections for my application.
I’m having to (belatedly) implement Memcache, for a number of reasons. I’ve started to figure it out but want to confirm one thing.
I was hoping to make amendments to class with defaults on timeout. It sees if it’s in memcache, if not – make the query and store it.
However, it appears as though you can’t store mysqli results (via this question). Does that mean you can’t use any code in the application which says $db->fetch_assoc() or any other general object uses?
If so, does this mean we’re talking ground up code change across the board? I want to confirm before I put my head in my hands.
You cannot store the result object, no, but you can fetch all rows into an array and store that array. If you need refactoring of your code in other places depends on how you have written your code and how well you have abstracted database access earlier.
For example, if you have a function like this:
Then you can add Memcached caching inside that function:
If you use the raw PDO or MySQLi object everywhere, then you have more work to do.