Peek at the top of the stack in the cache.

    :param cache: werkzeug BasicCache-like object
    :param user_id: id of user, used as key in cache

    :return: top item in user's cached stack, otherwise None
514567
def top_stream(cache, user_id):
    
    if not user_id:
        return None
    
    stack = cache.get(user_id)
    if stack is None:
        return None
    return stack.pop()
1362678
function getCachedMountContext(blockchain_id) {

   let userData = getUserData();
   if (!userData.datastore_contexts) {
      console.log("No datastore contexts defined");
      return null;
   }

   if (!userData.datastore_contexts[blockchain_id]) {
      console.log(`No datastore contexts for ${blockchain_id}`);
      return null;
   }

   let ctx = userData.datastore_contexts[blockchain_id];
   if (!ctx) {
      console.log(`Null datastore context for ${blockchain_id}`);
      return null;
   }

   return ctx;
}
427050
def select_io( hash ):
    
    load_cache(True)
    global CACHE_
    res = []
    record_used('cache', hash)
    for d in CACHE_['cache'].get(hash, {}).values():
        d = pickle.loads(d)
        res += [(d['hash'], d['stack'], d['methodname'], d['returnval'], d['args'], d['packet_num'])]
    return res
66099
def _get_parent_id_list(self, qualifier_id, hierarchy_id):
        
        if self._caching_enabled():
            key = 'parent_id_list_{0}'.format(str(qualifier_id))

            # If configured to use memcache as the caching engine, use it.
            # Otherwise default to diskcache
            caching_engine = 'diskcache'

            try:
                config = self._runtime.get_configuration()
                parameter_id = Id('parameter:cachingEngine@json')
                caching_engine = config.get_value_by_parameter(parameter_id).get_string_value()
            except (AttributeError, KeyError, errors.NotFound):
                pass

            if caching_engine == 'memcache':
                import memcache
                caching_host = '127.0.0.1:11211'
                try:
                    config = self._runtime.get_configuration()
                    parameter_id = Id('parameter:cachingHostURI@json')
                    caching_host = config.get_value_by_parameter(parameter_id).get_string_value()
                except (AttributeError, KeyError, errors.NotFound):
                    pass
                mc = memcache.Client([caching_host], debug=0)
                parent_id_list = mc.get(key)
                if parent_id_list is None:
                    parent_ids = self._get_hierarchy_session(hierarchy_id).get_parents(qualifier_id)
                    parent_id_list = [str(parent_id) for parent_id in parent_ids]
                    mc.set(key, parent_id_list)

            elif caching_engine == 'diskcache':
                import diskcache
                with diskcache.Cache('/tmp/dlkit_cache') as cache:
                    # A little bit non-DRY, since it's almost the same as for memcache above.
                    # However, for diskcache.Cache, we have to call ".close()" or use a
                    #   ``with`` statement to safeguard calling ".close()", so we keep this
                    #   separate from the memcache implementation.
                    parent_id_list = cache.get(key)
                    if parent_id_list is None:
                        parent_ids = self._get_hierarchy_session(hierarchy_id).get_parents(qualifier_id)
                        parent_id_list = [str(parent_id) for parent_id in parent_ids]
                        cache.set(key, parent_id_list)
            else:
                raise errors.NotFound('The {0} caching engine was not found.'.format(caching_engine))
        else:
            parent_ids = self._get_hierarchy_session(hierarchy_id).get_parents(qualifier_id)
            parent_id_list = [str(parent_id) for parent_id in parent_ids]
        return parent_id_list
294813
def _prime_user_perm_caches(self):
        
        perm_cache, group_perm_cache = self._get_user_cached_perms()
        self.user._authority_perm_cache = perm_cache
        self.user._authority_group_perm_cache = group_perm_cache
        self.user._authority_perm_cache_filled = True
288764
private final synchronized CacheElement getCacheElement(String userid) {
        String m = getCacheAbbrev() + " getCacheElement() ";
        CacheElement cacheElement = null;
        String key = getKey(userid);
        logger.debug(m + "key==" + key);
        if (cache.containsKey(key)) {
            logger.debug(m + "cache already has element");
        } else {
            logger.debug(m + "cache does not have element; create and put");
            CacheElement itemtemp =
                    new CacheElement(userid, getCacheId(), getCacheAbbrev());
            cache.put(key, itemtemp);
        }
        cacheElement = (CacheElement) cache.get(key);
        if (cacheElement == null) {
            logger.error(m + "cache does not contain element");
        } else {
            logger.debug(m + "element retrieved from cache successfully");
        }
        return cacheElement;
    }
837446
public void addUserToCache(User user) {
        users.compute(user.getId(), (key, value) -> {
            Optional.ofNullable(value)
                    .map(Reference::get)
                    .filter(oldUser -> oldUser != user)
                    .map(Cleanupable.class::cast)
                    .ifPresent(Cleanupable::cleanup);

            WeakReference<User> result = new WeakReference<>(user, usersCleanupQueue);
            userIdByRef.put(result, key);
            return result;
        });
    }
367923
def get_user(self, user_id):
        
        if user_id in self._users:
            return self._users.get(user_id)
        else:
            # Load user
            # Save user in cache
            return
519397
def get_cache_key(page):
    
    try:
        site_id = page.node.site_id
    except AttributeError:
        site_id = page.site_id
    return _get_cache_key('page_sitemap', page, 'default', site_id)
119753
def prepare_cache_id(self, combined_args_kw):
        ""
        cache_id = "".join(self.id(a) for a in combined_args_kw)
        return cache_id
1267595
def QA_fetch_user(user_cookie, db=DATABASE):
    
    collection = DATABASE.account

    return [res for res in collection.find({'user_cookie': user_cookie}, {"_id": 0})]
1306268
def get_cache(self, request):
        

        # try and get the cached GET response
        cache_key = self.cache_key(request)
        cached_response = cache.get(cache_key, None)
        # if it wasn't found and we are looking for a HEAD, try looking for a corresponding GET
        if cached_response is None and request.method == 'HEAD':
            cache_key = self.cache_key(request, 'GET')
            cached_response = cache.get(cache_key, None)
        if cached_response is None:
            return None, None
        if cached_response[1] < time.time() - settings.BETTERCACHE_LOCAL_POSTCHECK:
            return cached_response[0], True
        return cached_response[0], False
273700
def _cache_key_select_user(method, self, allow_blank=True, style=None):
    
    key = update_timer(), allow_blank, style
    return key
1214139
def get_cache_key(request, meta, orgaMode, currentOrga):
    """"""

    # Caching
    cacheKey = None

    if 'cache_time' in meta:
        if meta['cache_time'] > 0:

            # by default, no cache by user
            useUser = False

            # If a logged user in needed, cache the result by user
            if ('only_logged_user' in meta and meta['only_logged_user']) or \
                    ('only_member_user' in meta and meta['only_member_user']) or \
                    ('only_admin_user' in meta and meta['only_admin_user']) or \
                    ('only_orga_member_user' in meta and meta['only_orga_member_user']) or \
                    ('only_orga_admin_user' in meta and meta['only_orga_admin_user']):
                useUser = True

            # If a value if present in meta, use it
            if 'cache_by_user' in meta:
                useUser = meta['cache_by_user']

            cacheKey = '-'

            # Add user info if needed
            if useUser:
                cacheKey += str(request.user.pk) + 'usr-'

            # Add orga
            if orgaMode:
                cacheKey += str(currentOrga.pk) + 'org-'

            # Add current query
            cacheKey += request.get_full_path()

            # Add current template (if the template changed, cache must be invalided)
            cacheKey += meta['template_tag']

    return cacheKey
522228
def _update_request_context_with_user(self, user=None):
        ''''''

        ctx = _request_ctx_stack.top
        ctx.user = self.anonymous_user() if user is None else user
644481
private User getFromCache(String userName)
   {
      return (User)cache.get(userName, CacheType.USER);
   }
750393
public static int getUnReadCount(final Long _userId)
    {
        int ret = 0;
        if (MessageStatusHolder.CACHE.userID2UnRead.containsKey(_userId)) {
            ret = MessageStatusHolder.CACHE.userID2UnRead.get(_userId);
        }
        return ret;
    }