'Wrapper around QuerySet.get which supports caching of the
intermediate value.  Callee is responsible for making sure
the cache key is cleared on save.'

def get_from_cache(self, **kwargs):

    if ((not self.cache_fields) or (len(kwargs) > 1)):
        return self.get(**kwargs)
    (key, value) = next(six.iteritems(kwargs))
    pk_name = self.model._meta.pk.name
    if (key == 'pk'):
        key = pk_name
    if isinstance(value, Model):
        value = value.pk
    if key.endswith('__exact'):
        key = key.split('__exact', 1)[0]
    if ((key in self.cache_fields) or (key == pk_name)):
        cache_key = self.__get_lookup_cache_key(**{key: value})
        retval = cache.get(cache_key, version=self.cache_version)
        if (retval is None):
            result = self.get(**kwargs)
            self.__post_save(instance=result)
            return result
        if (key != pk_name):
            return self.get_from_cache(**{pk_name: retval})
        if (type(retval) != self.model):
            if settings.DEBUG:
                raise ValueError('Unexpected    value    type    returned    from    cache')
            logger.error('Cache    response    returned    invalid    value    %r', retval)
            return self.get(**kwargs)
        if ((key == pk_name) and (int(value) != retval.pk)):
            if settings.DEBUG:
                raise ValueError('Unexpected    value    returned    from    cache')
            logger.error('Cache    response    returned    invalid    value    %r', retval)
            return self.get(**kwargs)
        retval._state.db = router.db_for_read(self.model, **kwargs)
        return retval
    else:
        return self.get(**kwargs)
