Error is: Failed storing data in memcached, error code: 20
use Phalcon\Mvc\User\Component;
use Phalcon\DI;
use Phalcon\Cache\Frontend\Data as FrontData;
use Phalcon\Cache\Backend\Libmemcached as BackMemCached;
use Phalcon\Mvc\Model\Message;
class Universe extends Component {
protected function buildCache() {
$sdk = $this->getDi()->getShared('sdkaccount');
$region = $this->getDi()->getShared('session')->get('current_region');
$params = [
'brands' => null,
'packages' => null,
'groups' => null
];
$getParams = [
'region' => $region->code
];
$sdk_response = $sdk->post("AudienceProfile/Region", $params, $getParams);
if ($sdk_response->result != "success") {
$this->appendMessage(new Message($sdk_response->message));
return false;
}
$this->buildCacheData($sdk_response,"public");
return true;
}
protected function buildCacheData($sdk_response,$type) {
$cache = $this->getCache();
$brands = $sdk_response->metadata->brands;
$packages = $sdk_response->metadata->packages;
$groups = $sdk_response->metadata->groups;
$audiences = $sdk_response->data;
if ($type == "private") {
$user = DI::getDefault()->getSession()->get('auth_user');
$cache->save("privatebrands".$user->account_id,$brands);
$cache->save("privatepackages".$user->account_id,$packages);
$cache->save("privategroups".$user->account_id,$groups);
$cache->save("privateaudiences".$user->account_id,$audiences);
} else {
//// It's dying here
$cache->save("publicbrands",$brands);
$cache->save("publicpackages",$packages);
$cache->save("publicgroups",$groups);
$cache->save("publicaudiences",$audiences);
}
return true;
}
protected function getCache() {
$frontCache = new FrontData([
"lifetime" => 900 //15 minutes
]);
$cache = new BackMemCached(
$frontCache,
[
"servers" => [
"host" => "127.0.0.1",
"port" => "11211",
"weight" => "1"
]
]
);
return $cache;
}
public function getGroups($arrGroupIDs) {
$user = DI::getDefault()->getSession()->get('auth_user');
$cache = $this->getCache();
$arr = [];
$groups = $cache->get("publicgroups");
if (empty($groups)) {
if (!$this->buildCache()) {
return false;
}
$groups = $cache->get("publicgroups");
}
foreach ($arrGroupIDs as $groupID) {
foreach($groups as $group) {
var_dump($group,$groupID);
die();
}
}
return $arr;
}
}
It's dying calling $cache->save("publicbrands",$brands); What am I doing wrong?