+ def _add_to_cache(self, using, node, qs=None):
+ key = getattr(node, 'pk', None)
+
+ if qs is None:
+ if key is None:
+ roots = self.none()
+ else:
+ roots = node.hosted_navigation.select_related('target_node')
+
+ for root in roots:
+ root_qs = root.get_descendants(include_self=True).complex_filter({'%s__lte' % root._mptt_meta.level_attr: root.get_level() + root.depth}).exclude(depth__isnull=True)
+ if qs is None:
+ qs = root_qs
+ else:
+ qs |= root_qs
+
+ if qs is None:
+ qs = self.none()
+
+ self.__class__._cache.setdefault(using, {})[key] = qs
+
+ def _get_from_cache(self, using, node):
+ key = getattr(node, 'pk', None)
+ return self.__class__._cache[self.db][key]
+
+ def _is_cached(self, using, node):
+ try:
+ self._get_from_cache(using, node)
+ except KeyError:
+ return False
+ return True
+