{"action":"created","comment":{"url":"https://api.github.com/repos/koala-framework/koala-framework/pulls/comments/76014728","id":76014728,"diff_hunk":"@@ -0,0 +1,324 @@\n+<?php\n+class Kwf_Component_Cache_Redis extends Kwf_Component_Cache\n+{\n+    protected $_redis;\n+    public function __construct()\n+    {\n+        $this->_redis = Kwf_Cache_Simple::getRedis();\n+    }\n+\n+    public function save(Kwf_Component_Data $component, $contents, $renderer, $type, $value, $tag, $lifetime)\n+    {\n+        $key = self::_getCacheId($component->componentId, $renderer, $type, $value);\n+\n+        $this->_redis->sAdd('viewids:componentid:'.$component->componentId, $key);\n+        $this->_redis->sAdd('viewids:dbid:'.$component->dbId, $key);\n+        $this->_redis->sAdd('viewids:pagedbid:'.$component->getPageOrRoot()->dbId, $key);\n+        $this->_redis->sAdd('viewids:cls:'.$component->componentClass, $key);\n+        if ($tag) {\n+            $this->_redis->sAdd('viewids:tag:'.$tag, $key);\n+        }\n+\n+        $parts = preg_split('/([_\\-])/', $component->getExpandedComponentId(), -1, PREG_SPLIT_DELIM_CAPTURE);\n+        $id = '';\n+        foreach ($parts as $part) {\n+            $id .= $part;\n+            if ($part != '-' && $part != '_' && $id != 'root') {\n+                $this->_redis->sAdd('viewids:recexpandedid:'.$id, $key);\n+            }\n+        }\n+\n+        $cacheContent = array(\n+            'contents' => $contents,\n+            'expire' => is_null($lifetime) ? null : time()+$lifetime\n+        );\n+\n+        if (is_null($lifetime)) {\n+            //Set a TTL for view contents http://stackoverflow.com/questions/16370278/how-to-make-redis-choose-lru-eviction-policy-for-only-some-of-the-keys\n+            $lifetime = 365*24*60*60;\n+        }\n+        $ret = $this->_redis->setEx($key, $lifetime, serialize($cacheContent));\n+\n+        return $ret;\n+    }\n+\n+    public function load($componentId, $renderer='component', $type = 'component', $value = '')\n+    {\n+        $data = $this->loadWithMetadata($componentId, $renderer, $type, $value);\n+        if ($data === null) return $data;\n+        return $data['contents'];\n+    }\n+\n+    public function loadWithMetadata($componentId, $renderer='component', $type = 'component', $value = '')\n+    {\n+        if ($componentId instanceof Kwf_Component_Data) {\n+            $componentId = $componentId->componentId;\n+        }\n+        $key = self::_getCacheId($componentId, $renderer, $type, $value);\n+        $ret = unserialize($this->_redis->get($key));\n+        return $ret;\n+    }\n+\n+    private function _deleteViewCache(array $updates, $dryRun)\n+    {\n+        $sets = array(\n+            'component_id' => array(\n+                'prefix' => 'viewids:componentid:'\n+            ),\n+            'db_id' => array(\n+                'prefix' => 'viewids:dbid:'\n+            ),\n+            'page_db_id' => array(\n+                'prefix' => 'viewids:pagedbid:'\n+            ),\n+            'component_class' => array(\n+                'prefix' => 'viewids:cls:'\n+            ),\n+            'tag' => array(\n+                'prefix' => 'viewids:tag:'\n+            ),\n+            'expanded_component_id' => array(\n+                'prefix' => 'viewids:expandedid:'","path":"Kwf/Component/Cache/Redis.php","position":81,"original_position":81,"commit_id":"98d7ed7dc9c31b1a90b0611ec13b3dbfb217bdab","original_commit_id":"98d7ed7dc9c31b1a90b0611ec13b3dbfb217bdab","user":{"login":"fraxachun","id":1013756,"avatar_url":"https://avatars.githubusercontent.com/u/1013756?v=3","gravatar_id":"","url":"https://api.github.com/users/fraxachun","html_url":"https://github.com/fraxachun","followers_url":"https://api.github.com/users/fraxachun/followers","following_url":"https://api.github.com/users/fraxachun/following{/other_user}","gists_url":"https://api.github.com/users/fraxachun/gists{/gist_id}","starred_url":"https://api.github.com/users/fraxachun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fraxachun/subscriptions","organizations_url":"https://api.github.com/users/fraxachun/orgs","repos_url":"https://api.github.com/users/fraxachun/repos","events_url":"https://api.github.com/users/fraxachun/events{/privacy}","received_events_url":"https://api.github.com/users/fraxachun/received_events","type":"User","site_admin":false},"body":"recexpandedid","created_at":"2016-08-24T08:34:21Z","updated_at":"2016-08-24T08:34:21Z","html_url":"https://github.com/koala-framework/koala-framework/pull/554#discussion_r76014728","pull_request_url":"https://api.github.com/repos/koala-framework/koala-framework/pulls/554","_links":{"self":{"href":"https://api.github.com/repos/koala-framework/koala-framework/pulls/comments/76014728"},"html":{"href":"https://github.com/koala-framework/koala-framework/pull/554#discussion_r76014728"},"pull_request":{"href":"https://api.github.com/repos/koala-framework/koala-framework/pulls/554"}}},"pull_request":{"url":"https://api.github.com/repos/koala-framework/koala-framework/pulls/554","id":82221260,"html_url":"https://github.com/koala-framework/koala-framework/pull/554","diff_url":"https://github.com/koala-framework/koala-framework/pull/554.diff","patch_url":"https://github.com/koala-framework/koala-framework/pull/554.patch","issue_url":"https://api.github.com/repos/koala-framework/koala-framework/issues/554","number":554,"state":"open","locked":false,"title":"Add support for redis as alternative for memcache","user":{"login":"nsams","id":50764,"avatar_url":"https://avatars.githubusercontent.com/u/50764?v=3","gravatar_id":"","url":"https://api.github.com/users/nsams","html_url":"https://github.com/nsams","followers_url":"https://api.github.com/users/nsams/followers","following_url":"https://api.github.com/users/nsams/following{/other_user}","gists_url":"https://api.github.com/users/nsams/gists{/gist_id}","starred_url":"https://api.github.com/users/nsams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nsams/subscriptions","organizations_url":"https://api.github.com/users/nsams/orgs","repos_url":"https://api.github.com/users/nsams/repos","events_url":"https://api.github.com/users/nsams/events{/privacy}","received_events_url":"https://api.github.com/users/nsams/received_events","type":"User","site_admin":false},"body":"Advantage is that we can drop mysql for clearing cache as we can create an index in redis","created_at":"2016-08-22T16:25:24Z","updated_at":"2016-08-24T08:34:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5a268bfaa57302475ce402a7847ffb02f15439db","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/koala-framework/koala-framework/pulls/554/commits","review_comments_url":"https://api.github.com/repos/koala-framework/koala-framework/pulls/554/comments","review_comment_url":"https://api.github.com/repos/koala-framework/koala-framework/pulls/comments{/number}","comments_url":"https://api.github.com/repos/koala-framework/koala-framework/issues/554/comments","statuses_url":"https://api.github.com/repos/koala-framework/koala-framework/statuses/98d7ed7dc9c31b1a90b0611ec13b3dbfb217bdab","head":{"label":"nsams:redis-view-cache","ref":"redis-view-cache","sha":"98d7ed7dc9c31b1a90b0611ec13b3dbfb217bdab","user":{"login":"nsams","id":50764,"avatar_url":"https://avatars.githubusercontent.com/u/50764?v=3","gravatar_id":"","url":"https://api.github.com/users/nsams","html_url":"https://github.com/nsams","followers_url":"https://api.github.com/users/nsams/followers","following_url":"https://api.github.com/users/nsams/following{/other_user}","gists_url":"https://api.github.com/users/nsams/gists{/gist_id}","starred_url":"https://api.github.com/users/nsams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nsams/subscriptions","organizations_url":"https://api.github.com/users/nsams/orgs","repos_url":"https://api.github.com/users/nsams/repos","events_url":"https://api.github.com/users/nsams/events{/privacy}","received_events_url":"https://api.github.com/users/nsams/received_events","type":"User","site_admin":false},"repo":{"id":6918151,"name":"koala-framework","full_name":"nsams/koala-framework","owner":{"login":"nsams","id":50764,"avatar_url":"https://avatars.githubusercontent.com/u/50764?v=3","gravatar_id":"","url":"https://api.github.com/users/nsams","html_url":"https://github.com/nsams","followers_url":"https://api.github.com/users/nsams/followers","following_url":"https://api.github.com/users/nsams/following{/other_user}","gists_url":"https://api.github.com/users/nsams/gists{/gist_id}","starred_url":"https://api.github.com/users/nsams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nsams/subscriptions","organizations_url":"https://api.github.com/users/nsams/orgs","repos_url":"https://api.github.com/users/nsams/repos","events_url":"https://api.github.com/users/nsams/events{/privacy}","received_events_url":"https://api.github.com/users/nsams/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nsams/koala-framework","description":"Framework and CMS based on Zend Framework and ExtJS","fork":true,"url":"https://api.github.com/repos/nsams/koala-framework","forks_url":"https://api.github.com/repos/nsams/koala-framework/forks","keys_url":"https://api.github.com/repos/nsams/koala-framework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nsams/koala-framework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nsams/koala-framework/teams","hooks_url":"https://api.github.com/repos/nsams/koala-framework/hooks","issue_events_url":"https://api.github.com/repos/nsams/koala-framework/issues/events{/number}","events_url":"https://api.github.com/repos/nsams/koala-framework/events","assignees_url":"https://api.github.com/repos/nsams/koala-framework/assignees{/user}","branches_url":"https://api.github.com/repos/nsams/koala-framework/branches{/branch}","tags_url":"https://api.github.com/repos/nsams/koala-framework/tags","blobs_url":"https://api.github.com/repos/nsams/koala-framework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nsams/koala-framework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nsams/koala-framework/git/refs{/sha}","trees_url":"https://api.github.com/repos/nsams/koala-framework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nsams/koala-framework/statuses/{sha}","languages_url":"https://api.github.com/repos/nsams/koala-framework/languages","stargazers_url":"https://api.github.com/repos/nsams/koala-framework/stargazers","contributors_url":"https://api.github.com/repos/nsams/koala-framework/contributors","subscribers_url":"https://api.github.com/repos/nsams/koala-framework/subscribers","subscription_url":"https://api.github.com/repos/nsams/koala-framework/subscription","commits_url":"https://api.github.com/repos/nsams/koala-framework/commits{/sha}","git_commits_url":"https://api.github.com/repos/nsams/koala-framework/git/commits{/sha}","comments_url":"https://api.github.com/repos/nsams/koala-framework/comments{/number}","issue_comment_url":"https://api.github.com/repos/nsams/koala-framework/issues/comments{/number}","contents_url":"https://api.github.com/repos/nsams/koala-framework/contents/{+path}","compare_url":"https://api.github.com/repos/nsams/koala-framework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nsams/koala-framework/merges","archive_url":"https://api.github.com/repos/nsams/koala-framework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nsams/koala-framework/downloads","issues_url":"https://api.github.com/repos/nsams/koala-framework/issues{/number}","pulls_url":"https://api.github.com/repos/nsams/koala-framework/pulls{/number}","milestones_url":"https://api.github.com/repos/nsams/koala-framework/milestones{/number}","notifications_url":"https://api.github.com/repos/nsams/koala-framework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nsams/koala-framework/labels{/name}","releases_url":"https://api.github.com/repos/nsams/koala-framework/releases{/id}","deployments_url":"https://api.github.com/repos/nsams/koala-framework/deployments","created_at":"2012-11-29T09:14:47Z","updated_at":"2015-01-18T02:50:27Z","pushed_at":"2016-08-23T07:19:56Z","git_url":"git://github.com/nsams/koala-framework.git","ssh_url":"git@github.com:nsams/koala-framework.git","clone_url":"https://github.com/nsams/koala-framework.git","svn_url":"https://github.com/nsams/koala-framework","homepage":"http://www.koala-framework.org/","size":66630,"stargazers_count":1,"watchers_count":1,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"koala-framework:4.2","ref":"4.2","sha":"9e8195c83f1c31535c4f8ddaab4e51f3ed9ac90e","user":{"login":"koala-framework","id":7679767,"avatar_url":"https://avatars.githubusercontent.com/u/7679767?v=3","gravatar_id":"","url":"https://api.github.com/users/koala-framework","html_url":"https://github.com/koala-framework","followers_url":"https://api.github.com/users/koala-framework/followers","following_url":"https://api.github.com/users/koala-framework/following{/other_user}","gists_url":"https://api.github.com/users/koala-framework/gists{/gist_id}","starred_url":"https://api.github.com/users/koala-framework/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/koala-framework/subscriptions","organizations_url":"https://api.github.com/users/koala-framework/orgs","repos_url":"https://api.github.com/users/koala-framework/repos","events_url":"https://api.github.com/users/koala-framework/events{/privacy}","received_events_url":"https://api.github.com/users/koala-framework/received_events","type":"Organization","site_admin":false},"repo":{"id":2466955,"name":"koala-framework","full_name":"koala-framework/koala-framework","owner":{"login":"koala-framework","id":7679767,"avatar_url":"https://avatars.githubusercontent.com/u/7679767?v=3","gravatar_id":"","url":"https://api.github.com/users/koala-framework","html_url":"https://github.com/koala-framework","followers_url":"https://api.github.com/users/koala-framework/followers","following_url":"https://api.github.com/users/koala-framework/following{/other_user}","gists_url":"https://api.github.com/users/koala-framework/gists{/gist_id}","starred_url":"https://api.github.com/users/koala-framework/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/koala-framework/subscriptions","organizations_url":"https://api.github.com/users/koala-framework/orgs","repos_url":"https://api.github.com/users/koala-framework/repos","events_url":"https://api.github.com/users/koala-framework/events{/privacy}","received_events_url":"https://api.github.com/users/koala-framework/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/koala-framework/koala-framework","description":"Framework and CMS based on Zend Framework and ExtJS","fork":false,"url":"https://api.github.com/repos/koala-framework/koala-framework","forks_url":"https://api.github.com/repos/koala-framework/koala-framework/forks","keys_url":"https://api.github.com/repos/koala-framework/koala-framework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/koala-framework/koala-framework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/koala-framework/koala-framework/teams","hooks_url":"https://api.github.com/repos/koala-framework/koala-framework/hooks","issue_events_url":"https://api.github.com/repos/koala-framework/koala-framework/issues/events{/number}","events_url":"https://api.github.com/repos/koala-framework/koala-framework/events","assignees_url":"https://api.github.com/repos/koala-framework/koala-framework/assignees{/user}","branches_url":"https://api.github.com/repos/koala-framework/koala-framework/branches{/branch}","tags_url":"https://api.github.com/repos/koala-framework/koala-framework/tags","blobs_url":"https://api.github.com/repos/koala-framework/koala-framework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/koala-framework/koala-framework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/koala-framework/koala-framework/git/refs{/sha}","trees_url":"https://api.github.com/repos/koala-framework/koala-framework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/koala-framework/koala-framework/statuses/{sha}","languages_url":"https://api.github.com/repos/koala-framework/koala-framework/languages","stargazers_url":"https://api.github.com/repos/koala-framework/koala-framework/stargazers","contributors_url":"https://api.github.com/repos/koala-framework/koala-framework/contributors","subscribers_url":"https://api.github.com/repos/koala-framework/koala-framework/subscribers","subscription_url":"https://api.github.com/repos/koala-framework/koala-framework/subscription","commits_url":"https://api.github.com/repos/koala-framework/koala-framework/commits{/sha}","git_commits_url":"https://api.github.com/repos/koala-framework/koala-framework/git/commits{/sha}","comments_url":"https://api.github.com/repos/koala-framework/koala-framework/comments{/number}","issue_comment_url":"https://api.github.com/repos/koala-framework/koala-framework/issues/comments{/number}","contents_url":"https://api.github.com/repos/koala-framework/koala-framework/contents/{+path}","compare_url":"https://api.github.com/repos/koala-framework/koala-framework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/koala-framework/koala-framework/merges","archive_url":"https://api.github.com/repos/koala-framework/koala-framework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/koala-framework/koala-framework/downloads","issues_url":"https://api.github.com/repos/koala-framework/koala-framework/issues{/number}","pulls_url":"https://api.github.com/repos/koala-framework/koala-framework/pulls{/number}","milestones_url":"https://api.github.com/repos/koala-framework/koala-framework/milestones{/number}","notifications_url":"https://api.github.com/repos/koala-framework/koala-framework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/koala-framework/koala-framework/labels{/name}","releases_url":"https://api.github.com/repos/koala-framework/koala-framework/releases{/id}","deployments_url":"https://api.github.com/repos/koala-framework/koala-framework/deployments","created_at":"2011-09-27T10:36:51Z","updated_at":"2016-05-06T22:10:43Z","pushed_at":"2016-08-23T07:19:56Z","git_url":"git://github.com/koala-framework/koala-framework.git","ssh_url":"git@github.com:koala-framework/koala-framework.git","clone_url":"https://github.com/koala-framework/koala-framework.git","svn_url":"https://github.com/koala-framework/koala-framework","homepage":"http://www.koala-framework.org/","size":76762,"stargazers_count":41,"watchers_count":41,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":28,"mirror_url":null,"open_issues_count":32,"forks":28,"open_issues":32,"watchers":41,"default_branch":"4.1"}},"_links":{"self":{"href":"https://api.github.com/repos/koala-framework/koala-framework/pulls/554"},"html":{"href":"https://github.com/koala-framework/koala-framework/pull/554"},"issue":{"href":"https://api.github.com/repos/koala-framework/koala-framework/issues/554"},"comments":{"href":"https://api.github.com/repos/koala-framework/koala-framework/issues/554/comments"},"review_comments":{"href":"https://api.github.com/repos/koala-framework/koala-framework/pulls/554/comments"},"review_comment":{"href":"https://api.github.com/repos/koala-framework/koala-framework/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/koala-framework/koala-framework/pulls/554/commits"},"statuses":{"href":"https://api.github.com/repos/koala-framework/koala-framework/statuses/98d7ed7dc9c31b1a90b0611ec13b3dbfb217bdab"}}}}
{"actor":{"display_login":"fraxachun"}}