예제 #1
0
            def get_cache_key(*args, **kwargs):
                # Calculating cache key based on func and arguments
                md5 = cross.md5()
                md5.update('%s.%s' % (func.__module__, func.__name__))
                # TODO: make it more civilized
                if extra is not None:
                    if isinstance(extra, (list, tuple)):
                        md5.update(':'.join(map(str, extra)))
                    else:
                        md5.update(str(extra))
                if args:
                    md5.update(repr(args))
                if kwargs:
                    md5.update(repr(sorted(kwargs.items())))

                return 'c:%s' % md5.hexdigest()
예제 #2
0
    def _cache_key(self, extra=''):
        """
        Compute a cache key for this queryset
        """
        md5 = cross.md5()
        md5.update('%s.%s' % (self.__class__.__module__, self.__class__.__name__))
        md5.update(stamp_fields(self.model)) # Protect from field list changes in model
        md5.update(stringify_query(self.query))
        # If query results differ depending on database
        if self._cacheprofile and not self._cacheprofile['db_agnostic']:
            md5.update(self.db)
        if extra:
            md5.update(str(extra))
        # 'flat' attribute changes results formatting for ValuesQuerySet
        if hasattr(self, 'flat'):
            md5.update(str(self.flat))

        return 'q:%s' % md5.hexdigest()
예제 #3
0
 def _key_to_filename(self, key):
     """
     Returns a filename corresponding to cache key
     """
     digest = cross.md5(key).hexdigest()
     return os.path.join(self._dir, digest[-2:], digest[:-2])
예제 #4
0
def stamp_fields(model):
    """
    Returns serialized description of model fields.
    """
    stamp = str([(f.name, f.attname, f.db_column, f.__class__) for f in model._meta.fields])
    return cross.md5(stamp).hexdigest()