def test_neighbors_cache_key(self): node = Node(id=1) self.assertEqual("Arc1", destinations_cache_key(Arc, node)) class SubArc(Arc): pass self.assertEqual("SubArc1", destinations_cache_key(SubArc, node))
def do_business(self): super(DeleteOwnerToBlobArcs, self).do_business() if self.result: cache_keys = [] if self._DeleteArcs__origin: cache_keys.append(IMG_CACHE_PREFIX + destinations_cache_key(self.arc_class, self._DeleteArcs__origin)) else: for arc in self.result: cache_keys.append(IMG_CACHE_PREFIX + destinations_cache_key(self.arc_class, arc.origin)) if self._DeleteArcs__destination: cache_keys.append(IMG_CACHE_PREFIX + origins_cache_key(self.arc_class, self._DeleteArcs__destination)) else: for arc in self.result: cache_keys.append(IMG_CACHE_PREFIX + origins_cache_key(self.arc_class, arc.destination)) memcache.delete_multi(cache_keys)
def __init__(self, arc_class, origin=None, destination=None): super(DeleteArcs, self).__init__(arc_class, origin, destination, True) self._arc_delete_future = None self._cache_keys = [] if origin: self._cache_keys.append(destinations_cache_key(arc_class, origin)) if destination: self._cache_keys.append(origins_cache_key(arc_class, destination))
def test_destinations_search(self): origin = Node() destinations = [Node() for i in xrange(3)] ndb.put_multi([origin] + destinations) arcs = [Arc(origin=origin.key, destination=d.key) for d in destinations] ndb.put_multi(arcs) search = ArcDestinationsSearch(origin) search.execute() expected_keys = [n.key for n in destinations] actual_keys = [n.key for n in search.result] self.assertItemsEqual(expected_keys, actual_keys) cache_keys = memcache.get(destinations_cache_key(Arc, origin)) self.assertItemsEqual(expected_keys, cache_keys) # Assert Arcs are removed from cache Arc(origin=origin.key, destination=destinations[0].key).put() self.assertIsNone(memcache.get(destinations_cache_key(Arc, origin)))
def _pre_put_hook(self): if hasattr(self, 'key'): origins_key = origins_cache_key(self.__class__, self.destination) destinations_key = destinations_cache_key(self.__class__, self.origin) keys = [ origins_key, destinations_key, IMG_CACHE_PREFIX + origins_key, IMG_CACHE_PREFIX + destinations_key ] memcache.delete_multi(keys)
def do_business(self): super(DeleteArcs, self).do_business() if self.result: futures = ndb.delete_multi_async([arc.key for arc in self.result]) cache_keys = [] if self.__origin: cache_keys.append(destinations_cache_key(self.arc_class, self.__origin)) else: for arc in self.result: cache_keys.append(destinations_cache_key(self.arc_class, arc.origin)) if self.__destination: cache_keys.append(origins_cache_key(self.arc_class, self.__destination)) else: for arc in self.result: cache_keys.append(origins_cache_key(self.arc_class, arc.destination)) memcache.delete_multi(cache_keys) [f.get_result() for f in futures]
def __init__(self, arc_class, origin=None, destination=None): super(ArcNodeSearchBase, self).__init__(arc_class, origin, destination, False) if origin and destination: raise Exception('only one of origin or destination can be not None') elif origin: self._cache_key = destinations_cache_key(arc_class, origin) self._arc_property = 'destination' else: self._arc_property = 'origin' self._cache_key = origins_cache_key(arc_class, destination) self._node_cached_keys = None
def __init__(self, origin=None, destination=None): super(ArcNodeSearchBase, self).__init__(origin, destination, False) if origin and destination: raise Exception( 'only one of origin or destination can be not None') elif origin: self._cache_key = destinations_cache_key(self.arc_class, self.origin) self._arc_property = 'destination' else: self._arc_property = 'origin' self._cache_key = origins_cache_key(self.arc_class, destination) self._node_cached_keys = None
def do_business(self): super(DeleteArcs, self).do_business() if self.result: futures = ndb.delete_multi_async([arc.key for arc in self.result]) cache_keys = [] if self.__origin: cache_keys.append( destinations_cache_key(self.arc_class, self.__origin)) else: for arc in self.result: cache_keys.append( destinations_cache_key(self.arc_class, arc.origin)) if self.__destination: cache_keys.append( origins_cache_key(self.arc_class, self.__destination)) else: for arc in self.result: cache_keys.append( origins_cache_key(self.arc_class, arc.destination)) memcache.delete_multi(cache_keys) [f.get_result() for f in futures]
def do_business(self): super(DeleteOwnerToBlobArcs, self).do_business() if self.result: cache_keys = [] if self._DeleteArcs__origin: cache_keys.append(IMG_CACHE_PREFIX + destinations_cache_key( self.arc_class, self._DeleteArcs__origin)) else: for arc in self.result: cache_keys.append( IMG_CACHE_PREFIX + destinations_cache_key(self.arc_class, arc.origin)) if self._DeleteArcs__destination: cache_keys.append(IMG_CACHE_PREFIX + origins_cache_key( self.arc_class, self._DeleteArcs__destination)) else: for arc in self.result: cache_keys.append( IMG_CACHE_PREFIX + origins_cache_key(self.arc_class, arc.destination)) memcache.delete_multi(cache_keys)
def _pre_put_hook(self): if hasattr(self, 'key'): origins_key = origins_cache_key(self.__class__, self.destination) destinations_key = destinations_cache_key(self.__class__, self.origin) keys = [origins_key, destinations_key, IMG_CACHE_PREFIX + origins_key, IMG_CACHE_PREFIX + destinations_key] memcache.delete_multi(keys)