Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Transition Link objects to g.thingcache
Browse files Browse the repository at this point in the history
  • Loading branch information
bsimpson63 committed May 24, 2016
1 parent b69bf6e commit b47a387
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions r2/r2/lib/app_globals.py
Expand Up @@ -882,6 +882,26 @@ def setup(self):
self.thingcache = CacheChain((localcache_cls(), self.mcrouter))
cache_chains.update(thingcache=self.thingcache)

def get_new_link_prefix_and_key(key, prefix=''):
old_prefix = "Link_"
new_prefix = "link:"

if prefix:
assert prefix == old_prefix
return new_prefix, key
else:
key = str(key)
assert key.startswith(old_prefix)
link_id = key[len(old_prefix):]
return '', new_prefix + link_id

self.link_transitionalcache = TransitionalCache(
original_cache=self.cache,
replacement_cache=self.thingcache,
read_original=True,
key_transform=get_new_link_prefix_and_key,
)

if stalecaches:
self.memoizecache = StaleCacheChain(
localcache_cls(),
Expand Down
3 changes: 2 additions & 1 deletion r2/r2/models/link.py
Expand Up @@ -96,8 +96,9 @@

class LinkExists(Exception): pass

# defining types

class Link(Thing, Printable):
_cache = g.link_transitionalcache
_data_int_props = Thing._data_int_props + (
'num_comments', 'reported', 'comment_tree_id', 'gildings')
_defaults = dict(is_self=False,
Expand Down

0 comments on commit b47a387

Please sign in to comment.