{"action":"opened","issue":{"url":"https://api.github.com/repos/phalcon/cphalcon/issues/9932","labels_url":"https://api.github.com/repos/phalcon/cphalcon/issues/9932/labels{/name}","comments_url":"https://api.github.com/repos/phalcon/cphalcon/issues/9932/comments","events_url":"https://api.github.com/repos/phalcon/cphalcon/issues/9932/events","html_url":"https://github.com/phalcon/cphalcon/issues/9932","id":61800750,"number":9932,"title":"Phalcon\\Cache\\Backend\\Xcache delete method","user":{"login":"ErickSkrauch","id":4787256,"avatar_url":"https://avatars.githubusercontent.com/u/4787256?v=3","gravatar_id":"","url":"https://api.github.com/users/ErickSkrauch","html_url":"https://github.com/ErickSkrauch","followers_url":"https://api.github.com/users/ErickSkrauch/followers","following_url":"https://api.github.com/users/ErickSkrauch/following{/other_user}","gists_url":"https://api.github.com/users/ErickSkrauch/gists{/gist_id}","starred_url":"https://api.github.com/users/ErickSkrauch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ErickSkrauch/subscriptions","organizations_url":"https://api.github.com/users/ErickSkrauch/orgs","repos_url":"https://api.github.com/users/ErickSkrauch/repos","events_url":"https://api.github.com/users/ErickSkrauch/events{/privacy}","received_events_url":"https://api.github.com/users/ErickSkrauch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-03-15T11:47:28Z","updated_at":"2015-03-15T11:47:28Z","closed_at":null,"body":"I implemented for my project class to hold sessions in xcache and faced with the problem of the method of destruction session - it just doesn't work.\r\n\r\nI checked and everything definitively only possible reason may be the wrong behavior delete() method in the Backend\\Xcache.\r\n\r\nHere my class (based on Memcache from Phalcon incubator):\r\n\r\n```php\r\n<?php\r\nnamespace Ely\\Session\\Adapter;\r\n\r\nuse Phalcon;\r\nuse Phalcon\\Cache\\Frontend\\Data;\r\nuse Phalcon\\Cache\\Backend\\Xcache as XcacheConnection;\r\n\r\nclass Xcache extends Phalcon\\Session\\Adapter implements Phalcon\\Session\\AdapterInterface {\r\n\r\n    /**\r\n     * Default option for prefix of sessionId's\r\n     */\r\n    const DEFAULT_OPTION_PREFIX = 'session';\r\n\r\n    /**\r\n     * @var \\Phalcon\\Cache\\Backend\\Xcache\r\n     */\r\n    protected $xcacheInstance = null;\r\n\r\n    /**\r\n     * Class constructor.\r\n     *\r\n     * @param  null|array $options\r\n     * @throws Phalcon\\Session\\Exception\r\n     */\r\n    public function __construct($options = null) {\r\n        if (is_array($options)) {\r\n            if (!isset($options[\"prefix\"])) {\r\n                $options[\"prefix\"] = self::DEFAULT_OPTION_PREFIX;\r\n            }\r\n        } else {\r\n            throw new Phalcon\\Session\\Exception(\"No configuration given\");\r\n        }\r\n\r\n        session_set_save_handler(\r\n            array($this, 'open'),\r\n            array($this, 'close'),\r\n            array($this, 'read'),\r\n            array($this, 'write'),\r\n            array($this, 'destroy'),\r\n            array($this, 'gc')\r\n        );\r\n\r\n        parent::__construct($options);\r\n    }\r\n\r\n    /**\r\n     * Поскольку xcache не имеет механизма блокировки, то и в данных методах нет надобности\r\n     */\r\n    public function open() {\r\n        return true;\r\n    }\r\n\r\n    /**\r\n     * Поскольку xcache не имеет механизма блокировки, то и в данных методах нет надобности\r\n     */\r\n    public function close() {\r\n        return true;\r\n    }\r\n\r\n    public function read($sessionId) {\r\n        return $this->getXcacheInstance()->get($sessionId, $this->getOption('lifetime'));\r\n    }\r\n\r\n    public function write($sessionId, $data) {\r\n        $this->getXcacheInstance()->save($sessionId, $data, $this->getOption('lifetime'));\r\n    }\r\n\r\n    public function destroy($session_id = null) {\r\n        if (is_null($session_id)) {\r\n            $session_id = $this->getId();\r\n        }\r\n\r\n        return $this->getXcacheInstance()->delete($session_id);\r\n    }\r\n\r\n    /**\r\n     * Вообще без понятия что это и зачем нужно\r\n     */\r\n    public function gc() {\r\n    }\r\n\r\n    /**\r\n     * {@inheritdoc}\r\n     *\r\n     * @param  string $key\r\n     * @return mixed\r\n     */\r\n    public function getOption($key) {\r\n        $options = $this->getOptions();\r\n        if (isset($options[$key])) {\r\n            return $options[$key];\r\n        }\r\n\r\n        return NULL;\r\n    }\r\n\r\n    /**\r\n     * @return \\Phalcon\\Cache\\Backend\\Xcache\r\n     */\r\n    protected function getXcacheInstance() {\r\n        if ($this->xcacheInstance === null) {\r\n            $frontCache = new Data(array(\r\n                \"lifetime\" => $this->getOption(\"lifetime\")\r\n            ));\r\n\r\n            $this->xcacheInstance = new XcacheConnection($frontCache, array(\r\n                \"prefix\" => $this->getOption(\"prefix\")\r\n            ));\r\n        }\r\n\r\n        return $this->xcacheInstance;\r\n    }\r\n}\r\n```\r\n\r\nI went to the [source](https://github.com/phalcon/cphalcon/blob/master/ext/cache/backend/xcache.c) of my version (1.3.4) and saw the [following code](https://github.com/phalcon/cphalcon/blob/master/ext/cache/backend/xcache.c#L283). I don't understand how it's works and I went to the [source](https://github.com/phalcon/cphalcon/blob/2.0.0/phalcon/cache/backend/xcache.zep) to branch 2.0.0 and saw that's code:\r\n\r\n```php\r\n\tpublic function delete(var keyName)\r\n\t{\r\n\t\tvar prefixedKey, specialKey, keys;\r\n\r\n\t\tlet prefixedKey = \"_PHCX\" . this->_prefix . keyName;\r\n\r\n\t\tif !fetch specialKey, this->_options[\"statsKey\"] {\r\n\t\t\tthrow new Exception(\"Unexpected inconsistency in options\");\r\n\t\t}\r\n\r\n\t\tlet keys = xcache_get(specialKey);\r\n\t\tif typeof keys != \"array\" {\r\n\t\t\tlet keys = [];\r\n\t\t}\r\n\r\n\t\tunset keys[prefixedKey];\r\n\r\n\t\txcache_set(specialKey, keys);\r\n\t}\r\n```\r\n\r\nBut wait a minute, WHERE xcache_unset() o_O? On 1.3.4 branch i [saw some call](https://github.com/phalcon/cphalcon/blob/master/ext/cache/backend/xcache.c#L298) (but it's not work).\r\n\r\nWhy bother trying to get entry to be removed, for the something is assigned, but is not remove it?\r\n\r\n---------------\r\nErickSkrauch + Google Translate"}}