'Retrieve from cache or database (always caches)
Args:
key (str, optional): Tag key to query for
category (str, optional): Tag category
Returns:
args (list): Returns a list of zero or more matches
found from cache or database.
Notes:
When given a category only, a search for all objects
of that category is done and a the category *name* is is
stored. This tells the system on subsequent calls that the
list of cached tags of this category is up-to-date
and that the cache can be queried for category matches
without missing any.
The TYPECLASS_AGGRESSIVE_CACHE=False setting will turn off
caching, causing each tag access to trigger a
database lookup.'

def _getcache(self, key=None, category=None):

    key = (key.strip().lower() if key else None)
    category = (category.strip().lower() if category else None)
    if key:
        cachekey = ('%s-%s' % (key, category))
        tag = (_TYPECLASS_AGGRESSIVE_CACHE and self._cache.get(cachekey, None))
        if (tag and ((not hasattr(tag, 'pk')) and (tag.pk is None))):
            tag = None
            del self._cache[cachekey]
        if tag:
            return [tag]
        else:
            query = {('%s__id' % self._model): self._objid, 'tag__db_model': self._model, 'tag__db_tagtype': self._tagtype, 'tag__db_key__iexact': key.lower(), 'tag__db_category__iexact': (category.lower() if category else None)}
            conn = getattr(self.obj, self._m2m_fieldname).through.objects.filter(**query)
            if conn:
                tag = conn[0].tag
                self._cache[cachekey] = tag
                return [tag]
    else:
        catkey = ('-%s' % category)
        if (_TYPECLASS_AGGRESSIVE_CACHE and (catkey in self._catcache)):
            return [tag for (key, tag) in self._cache.items() if key.endswith(catkey)]
        else:
            query = {('%s__id' % self._model): self._objid, 'tag__db_model': self._model, 'tag__db_tagtype': self._tagtype, 'tag__db_category__iexact': (category.lower() if category else None)}
            tags = [conn.tag for conn in getattr(self.obj, self._m2m_fieldname).through.objects.filter(**query)]
            for tag in tags:
                cachekey = ('%s-%s' % (tag.db_key, category))
                self._cache[cachekey] = tag
            self._catcache[catkey] = True
            return tags
    return []
