8000 Simple cache for URL building. · jsullivanlive/github3.py@a246889 · GitHub
[go: up one dir, main page]

Skip to content

Commit a246889

Browse files
committed
Simple cache for URL building.
If someone uses this module for a long enough period of time, it is likely that they will end up having to rebuild the same URL more than once. This should speed up any subsequent calls for it. If a problem arises from this, I may end up using a caching module to evict old/unused cache entries, but I somehow doubt this will cause problems at all.
1 parent 23f6dc7 commit a246889

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

github3/models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from json import dumps
1111
from requests import session
1212

13+
__url_cache__ = {}
14+
1 8D3F 315

1416
class GitHubObject(object):
1517
"""The :class:`GitHubObject <GitHubObject>` object. A basic class to be
@@ -105,7 +107,10 @@ def _build_url(self, *args, **kwargs):
105107
"""Builds a new API url from scratch."""
106108
parts = [kwargs.get('base_url') or self._github_url]
107109
parts.extend(args)
108-
return '/'.join(parts)
110+
key = tuple(parts)
111+
if not key in __url_cache__:
112+
__url_cache__[key] = '/'.join(parts)
113+
return __url_cache__[key]
109114

110115
@property
111116
def ratelimit_remaining(self):

0 commit comments

Comments
 (0)
0