Permalink
Browse files

Refactor caching

  • Loading branch information...
1 parent 0d80338 commit 8adceb0ae20ba7510945bd31961f80466e785ae7 @jgorset committed May 14, 2012
Showing with 8 additions and 7 deletions.
  1. +1 −4 facebook/descriptors.py
  2. +7 −3 facebook/entity.py
View
@@ -11,10 +11,7 @@ def __init__(self, attribute):
self.attribute = attribute
def __get__(self, instance, owner):
- if not instance._cache:
- instance._cache = instance.load()
-
- return instance._cache[self.attribute]
+ return instance.cache[self.attribute]
class String(Descriptor):
View
@@ -19,9 +19,13 @@ def __init__(self, id, oauth_token=None):
self.oauth_token = oauth_token
self.id = id
- def load(self):
- """Query the Graph API for this resource."""
- return self.graph.get('%s' % self.id)
+ @property
+ def cache(self):
+ """Query or return the Graph API representation of this resource."""
+ if not self._cache:
+ self._cache = self.graph.get('%s' % self.id)
+
+ return self._cache
@property
def graph(self):

0 comments on commit 8adceb0

Please sign in to comment.