First, if it's a reusable "service", use getShared()
/ setShared()
on the DI
, otherwise you will end up creating a new instance every time you access it.
To actually retrieve it from anywhere in your app:
class Tags extends Phalcon\Mvc\Model {
protected function _getCache($key)
{
// how do i retreive memcached object?
$modelsChache = $this->di->getShared('modelsCache');
// Or if DI is not set on the model, though in 99.9% it will be unless you are doing something unusual.
$modelsChache = DI::getDefault()->getShared('modelsCache');
}
protected static function _setCache($key)
{
// stores data in the cache
// Same as above…
}