'Retrieve from cache or database (always caches)
Args:
key (str, optional): Attribute key to query for
category (str, optional): Attribiute 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 cateogory is done and a the category *name* is is
stored. This tells the system on subsequent calls that the
list of cached attributes 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 attribute 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))
        cachefound = False
        try:
            attr = (_TYPECLASS_AGGRESSIVE_CACHE and self._cache[cachekey])
            cachefound = True
        except KeyError:
            attr = None
        if (attr and ((not hasattr(attr, 'pk')) and (attr.pk is None))):
            attr = None
            cachefound = False
            del self._cache[cachekey]
        if cachefound:
            if attr:
                return [attr]
            else:
                return []
        else:
            query = {('%s__id' % self._model): self._objid, 'attribute__db_model__iexact': self._model, 'attribute__db_attrtype': self._attrtype, 'attribute__db_key__iexact': key.lower(), 'attribute__db_category__iexact': (category.lower() if category else None)}
            conn = getattr(self.obj, self._m2m_fieldname).through.objects.filter(**query)
            if conn:
                attr = conn[0].attribute
                self._cache[cachekey] = attr
                return ([attr] if attr.pk else [])
            else:
                self._cache[cachekey] = None
                return []
    else:
        catkey = ('-%s' % category)
        if (_TYPECLASS_AGGRESSIVE_CACHE and (catkey in self._catcache)):
            return [attr for (key, attr) in self._cache.items() if (key.endswith(catkey) and attr)]
        else:
            query = {('%s__id' % self._model): self._objid, 'attribute__db_model__iexact': self._model, 'attribute__db_attrtype': self._attrtype, 'attribute__db_category__iexact': (category.lower() if category else None)}
            attrs = [conn.attribute for conn in getattr(self.obj, self._m2m_fieldname).through.objects.filter(**query)]
            for attr in attrs:
                if attr.pk:
                    cachekey = ('%s-%s' % (attr.db_key, category))
                    self._cache[cachekey] = attr
            self._catcache[catkey] = True
            return attrs
