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

How is the $key that's passed to Phalcon\Mvc\Model\Manager::getReusableRecords() created?

I'm following the example found here https://docs.phalcon.io/en/latest/reference/models-cache.html#reusable-related-records to cache related models marked as 'reusable'. I've created my own custom model manager and it seems to be working fine, however is there a function or something that I can call to regenerate the key for a subsequent apc_delete() call somewhere else in the project? The $key that comes in looks similar to this:

MyProject\Model\User[[[user_id] = ?0,[123],O39]]

It's pretty easy to follow, so I could almost make it myself, just I'm confused what that 'O39' on the end is supposed to mean. Any ideas?



98.9k

O39 is an object with internal ID 39, if the same object is passed as part of $parameters it will use the same key later

edited Oct '14

Thanks for the reply. OK so that's basically constant then? Currently I've got a base model that all others in my project extend that looks something like this

    class MyBaseModel extends \Phalcon\Mvc\Model
        ... stuff ...
        public function afterSave() {
            $me = get_called_class();

            //if O39 never changes, then this should always match the cache $key
            $this->getDI()->get('modelsCache')->delete($me . '[[[id] = ?0,[' . (string)$this->id .  '],O39]]');  
        }
    }

I guess as long as it's always O39 that should be no problem then, yeah?