{"action":"created","comment":{"url":"https://api.github.com/repos/enthought/apptools/pulls/comments/24280022","id":24280022,"diff_hunk":"@@ -0,0 +1,155 @@\n+#!/usr/bin/env python\n+# -*- coding: utf-8 -*-\n+\n+from threading import RLock\n+import logging\n+\n+from traits.api import Callable, Dict, Event, HasStrictTraits, Instance, Int, \\\n+    List, Str\n+\n+logger = logging.getLogger(__name__)\n+\n+\n+class LRUCache(HasStrictTraits):\n+    \"\"\" A least-recently used cache.\n+\n+    Items older than `size()` accesses are dropped from the cache.\n+\n+    This is ported from python 3's functools.lru_cache.\n+\n+    \"\"\"\n+\n+    size = Int\n+\n+    # Called with the key and value that was dropped from the cache\n+    cache_drop_callback = Callable\n+\n+    # This event contains the set of cached cell keys whenever it changes\n+    updated = Event()\n+\n+    _lock = Instance(RLock, args=())\n+\n+    _cache = Dict\n+    _root = List\n+\n+    _tag = Str(\"LRUCache\")\n+\n+    def __init__(self, size, **traits):\n+        self.size = size\n+        self._cache = {}\n+        self._root = []  # root of the circular doubly linked list\n+        # initialize by pointing to self\n+        self._root[:] = [self._root, self._root, None, None]\n+        super(LRUCache, self).__init__(**traits)\n+\n+    # -------------------------------------------------------------------------\n+    # Traits defaults\n+    # -------------------------------------------------------------------------\n+\n+    def _cache_drop_callback_default(self):\n+        def callback(key, value):\n+            msg = \"Tag: {!r} cache drop {{{}: {}}}\"\n+            logger.debug(msg.format(self._tag, key, value))\n+        return callback","path":"apptools/lru_cache/lru_cache.py","position":53,"original_position":53,"commit_id":"aa199aeef9c80f5880316669644b2bbd87a45c59","original_commit_id":"aa199aeef9c80f5880316669644b2bbd87a45c59","user":{"login":"rkern","id":46135,"avatar_url":"https://avatars.githubusercontent.com/u/46135?v=3","gravatar_id":"","url":"https://api.github.com/users/rkern","html_url":"https://github.com/rkern","followers_url":"https://api.github.com/users/rkern/followers","following_url":"https://api.github.com/users/rkern/following{/other_user}","gists_url":"https://api.github.com/users/rkern/gists{/gist_id}","starred_url":"https://api.github.com/users/rkern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkern/subscriptions","organizations_url":"https://api.github.com/users/rkern/orgs","repos_url":"https://api.github.com/users/rkern/repos","events_url":"https://api.github.com/users/rkern/events{/privacy}","received_events_url":"https://api.github.com/users/rkern/received_events","type":"User","site_admin":false},"body":"I'd prefer nothing here.","created_at":"2015-02-06T23:18:17Z","updated_at":"2015-02-06T23:18:17Z","html_url":"https://github.com/enthought/apptools/pull/39#discussion_r24280022","pull_request_url":"https://api.github.com/repos/enthought/apptools/pulls/39","_links":{"self":{"href":"https://api.github.com/repos/enthought/apptools/pulls/comments/24280022"},"html":{"href":"https://github.com/enthought/apptools/pull/39#discussion_r24280022"},"pull_request":{"href":"https://api.github.com/repos/enthought/apptools/pulls/39"}}},"pull_request":{"url":"https://api.github.com/repos/enthought/apptools/pulls/39","id":28850260,"html_url":"https://github.com/enthought/apptools/pull/39","diff_url":"https://github.com/enthought/apptools/pull/39.diff","patch_url":"https://github.com/enthought/apptools/pull/39.patch","issue_url":"https://api.github.com/repos/enthought/apptools/issues/39","number":39,"state":"open","locked":false,"title":"Backport and traitsify python 3.x's functools.lru_cache","user":{"login":"johntyree","id":108972,"avatar_url":"https://avatars.githubusercontent.com/u/108972?v=3","gravatar_id":"","url":"https://api.github.com/users/johntyree","html_url":"https://github.com/johntyree","followers_url":"https://api.github.com/users/johntyree/followers","following_url":"https://api.github.com/users/johntyree/following{/other_user}","gists_url":"https://api.github.com/users/johntyree/gists{/gist_id}","starred_url":"https://api.github.com/users/johntyree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johntyree/subscriptions","organizations_url":"https://api.github.com/users/johntyree/orgs","repos_url":"https://api.github.com/users/johntyree/repos","events_url":"https://api.github.com/users/johntyree/events{/privacy}","received_events_url":"https://api.github.com/users/johntyree/received_events","type":"User","site_admin":false},"body":"This brings a `trait`'d `LRUCache` to python 2.x by adapting the decorator found in `functools.lru_cache` at https://hg.python.org/cpython/file/4d4a9094bdb0/Lib/functools.py","created_at":"2015-02-06T23:12:56Z","updated_at":"2015-02-06T23:18:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"98d21f197d718c2af7c2a1a9a50942cfa9f9d952","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/enthought/apptools/pulls/39/commits","review_comments_url":"https://api.github.com/repos/enthought/apptools/pulls/39/comments","review_comment_url":"https://api.github.com/repos/enthought/apptools/pulls/comments/{number}","comments_url":"https://api.github.com/repos/enthought/apptools/issues/39/comments","statuses_url":"https://api.github.com/repos/enthought/apptools/statuses/aa199aeef9c80f5880316669644b2bbd87a45c59","head":{"label":"enthought:enh/lru_cache","ref":"enh/lru_cache","sha":"aa199aeef9c80f5880316669644b2bbd87a45c59","user":{"login":"enthought","id":539651,"avatar_url":"https://avatars.githubusercontent.com/u/539651?v=3","gravatar_id":"","url":"https://api.github.com/users/enthought","html_url":"https://github.com/enthought","followers_url":"https://api.github.com/users/enthought/followers","following_url":"https://api.github.com/users/enthought/following{/other_user}","gists_url":"https://api.github.com/users/enthought/gists{/gist_id}","starred_url":"https://api.github.com/users/enthought/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/enthought/subscriptions","organizations_url":"https://api.github.com/users/enthought/orgs","repos_url":"https://api.github.com/users/enthought/repos","events_url":"https://api.github.com/users/enthought/events{/privacy}","received_events_url":"https://api.github.com/users/enthought/received_events","type":"Organization","site_admin":false},"repo":{"id":1301081,"name":"apptools","full_name":"enthought/apptools","owner":{"login":"enthought","id":539651,"avatar_url":"https://avatars.githubusercontent.com/u/539651?v=3","gravatar_id":"","url":"https://api.github.com/users/enthought","html_url":"https://github.com/enthought","followers_url":"https://api.github.com/users/enthought/followers","following_url":"https://api.github.com/users/enthought/following{/other_user}","gists_url":"https://api.github.com/users/enthought/gists{/gist_id}","starred_url":"https://api.github.com/users/enthought/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/enthought/subscriptions","organizations_url":"https://api.github.com/users/enthought/orgs","repos_url":"https://api.github.com/users/enthought/repos","events_url":"https://api.github.com/users/enthought/events{/privacy}","received_events_url":"https://api.github.com/users/enthought/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/enthought/apptools","description":"","fork":false,"url":"https://api.github.com/repos/enthought/apptools","forks_url":"https://api.github.com/repos/enthought/apptools/forks","keys_url":"https://api.github.com/repos/enthought/apptools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/enthought/apptools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/enthought/apptools/teams","hooks_url":"https://api.github.com/repos/enthought/apptools/hooks","issue_events_url":"https://api.github.com/repos/enthought/apptools/issues/events{/number}","events_url":"https://api.github.com/repos/enthought/apptools/events","assignees_url":"https://api.github.com/repos/enthought/apptools/assignees{/user}","branches_url":"https://api.github.com/repos/enthought/apptools/branches{/branch}","tags_url":"https://api.github.com/repos/enthought/apptools/tags","blobs_url":"https://api.github.com/repos/enthought/apptools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/enthought/apptools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/enthought/apptools/git/refs{/sha}","trees_url":"https://api.github.com/repos/enthought/apptools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/enthought/apptools/statuses/{sha}","languages_url":"https://api.github.com/repos/enthought/apptools/languages","stargazers_url":"https://api.github.com/repos/enthought/apptools/stargazers","contributors_url":"https://api.github.com/repos/enthought/apptools/contributors","subscribers_url":"https://api.github.com/repos/enthought/apptools/subscribers","subscription_url":"https://api.github.com/repos/enthought/apptools/subscription","commits_url":"https://api.github.com/repos/enthought/apptools/commits{/sha}","git_commits_url":"https://api.github.com/repos/enthought/apptools/git/commits{/sha}","comments_url":"https://api.github.com/repos/enthought/apptools/comments{/number}","issue_comment_url":"https://api.github.com/repos/enthought/apptools/issues/comments/{number}","contents_url":"https://api.github.com/repos/enthought/apptools/contents/{+path}","compare_url":"https://api.github.com/repos/enthought/apptools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/enthought/apptools/merges","archive_url":"https://api.github.com/repos/enthought/apptools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/enthought/apptools/downloads","issues_url":"https://api.github.com/repos/enthought/apptools/issues{/number}","pulls_url":"https://api.github.com/repos/enthought/apptools/pulls{/number}","milestones_url":"https://api.github.com/repos/enthought/apptools/milestones{/number}","notifications_url":"https://api.github.com/repos/enthought/apptools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/enthought/apptools/labels{/name}","releases_url":"https://api.github.com/repos/enthought/apptools/releases{/id}","created_at":"2011-01-27T23:49:03Z","updated_at":"2014-12-20T18:07:52Z","pushed_at":"2015-02-06T23:12:52Z","git_url":"git://github.com/enthought/apptools.git","ssh_url":"git@github.com:enthought/apptools.git","clone_url":"https://github.com/enthought/apptools.git","svn_url":"https://github.com/enthought/apptools","homepage":"","size":42583,"stargazers_count":15,"watchers_count":15,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":8,"mirror_url":null,"open_issues_count":5,"forks":8,"open_issues":5,"watchers":15,"default_branch":"master"}},"base":{"label":"enthought:master","ref":"master","sha":"ce84014094503ed782b98a912bb01d1b646fee87","user":{"login":"enthought","id":539651,"avatar_url":"https://avatars.githubusercontent.com/u/539651?v=3","gravatar_id":"","url":"https://api.github.com/users/enthought","html_url":"https://github.com/enthought","followers_url":"https://api.github.com/users/enthought/followers","following_url":"https://api.github.com/users/enthought/following{/other_user}","gists_url":"https://api.github.com/users/enthought/gists{/gist_id}","starred_url":"https://api.github.com/users/enthought/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/enthought/subscriptions","organizations_url":"https://api.github.com/users/enthought/orgs","repos_url":"https://api.github.com/users/enthought/repos","events_url":"https://api.github.com/users/enthought/events{/privacy}","received_events_url":"https://api.github.com/users/enthought/received_events","type":"Organization","site_admin":false},"repo":{"id":1301081,"name":"apptools","full_name":"enthought/apptools","owner":{"login":"enthought","id":539651,"avatar_url":"https://avatars.githubusercontent.com/u/539651?v=3","gravatar_id":"","url":"https://api.github.com/users/enthought","html_url":"https://github.com/enthought","followers_url":"https://api.github.com/users/enthought/followers","following_url":"https://api.github.com/users/enthought/following{/other_user}","gists_url":"https://api.github.com/users/enthought/gists{/gist_id}","starred_url":"https://api.github.com/users/enthought/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/enthought/subscriptions","organizations_url":"https://api.github.com/users/enthought/orgs","repos_url":"https://api.github.com/users/enthought/repos","events_url":"https://api.github.com/users/enthought/events{/privacy}","received_events_url":"https://api.github.com/users/enthought/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/enthought/apptools","description":"","fork":false,"url":"https://api.github.com/repos/enthought/apptools","forks_url":"https://api.github.com/repos/enthought/apptools/forks","keys_url":"https://api.github.com/repos/enthought/apptools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/enthought/apptools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/enthought/apptools/teams","hooks_url":"https://api.github.com/repos/enthought/apptools/hooks","issue_events_url":"https://api.github.com/repos/enthought/apptools/issues/events{/number}","events_url":"https://api.github.com/repos/enthought/apptools/events","assignees_url":"https://api.github.com/repos/enthought/apptools/assignees{/user}","branches_url":"https://api.github.com/repos/enthought/apptools/branches{/branch}","tags_url":"https://api.github.com/repos/enthought/apptools/tags","blobs_url":"https://api.github.com/repos/enthought/apptools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/enthought/apptools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/enthought/apptools/git/refs{/sha}","trees_url":"https://api.github.com/repos/enthought/apptools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/enthought/apptools/statuses/{sha}","languages_url":"https://api.github.com/repos/enthought/apptools/languages","stargazers_url":"https://api.github.com/repos/enthought/apptools/stargazers","contributors_url":"https://api.github.com/repos/enthought/apptools/contributors","subscribers_url":"https://api.github.com/repos/enthought/apptools/subscribers","subscription_url":"https://api.github.com/repos/enthought/apptools/subscription","commits_url":"https://api.github.com/repos/enthought/apptools/commits{/sha}","git_commits_url":"https://api.github.com/repos/enthought/apptools/git/commits{/sha}","comments_url":"https://api.github.com/repos/enthought/apptools/comments{/number}","issue_comment_url":"https://api.github.com/repos/enthought/apptools/issues/comments/{number}","contents_url":"https://api.github.com/repos/enthought/apptools/contents/{+path}","compare_url":"https://api.github.com/repos/enthought/apptools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/enthought/apptools/merges","archive_url":"https://api.github.com/repos/enthought/apptools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/enthought/apptools/downloads","issues_url":"https://api.github.com/repos/enthought/apptools/issues{/number}","pulls_url":"https://api.github.com/repos/enthought/apptools/pulls{/number}","milestones_url":"https://api.github.com/repos/enthought/apptools/milestones{/number}","notifications_url":"https://api.github.com/repos/enthought/apptools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/enthought/apptools/labels{/name}","releases_url":"https://api.github.com/repos/enthought/apptools/releases{/id}","created_at":"2011-01-27T23:49:03Z","updated_at":"2014-12-20T18:07:52Z","pushed_at":"2015-02-06T23:12:52Z","git_url":"git://github.com/enthought/apptools.git","ssh_url":"git@github.com:enthought/apptools.git","clone_url":"https://github.com/enthought/apptools.git","svn_url":"https://github.com/enthought/apptools","homepage":"","size":42583,"stargazers_count":15,"watchers_count":15,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":8,"mirror_url":null,"open_issues_count":5,"forks":8,"open_issues":5,"watchers":15,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/enthought/apptools/pulls/39"},"html":{"href":"https://github.com/enthought/apptools/pull/39"},"issue":{"href":"https://api.github.com/repos/enthought/apptools/issues/39"},"comments":{"href":"https://api.github.com/repos/enthought/apptools/issues/39/comments"},"review_comments":{"href":"https://api.github.com/repos/enthought/apptools/pulls/39/comments"},"review_comment":{"href":"https://api.github.com/repos/enthought/apptools/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/enthought/apptools/pulls/39/commits"},"statuses":{"href":"https://api.github.com/repos/enthought/apptools/statuses/aa199aeef9c80f5880316669644b2bbd87a45c59"}}}}