Cache put - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Cache put method.

This code example shows how to use the following methods:getIfPresent, put
This code example shows how to use the following methods:getIfPresent, put
            this.id = id;
            this.stats = stats;
        } 
 
        public T load(Factory<T> createIfNotPresent) {
            T out = cache.getIfPresent(id);
            if (out != null) {
                stats.readFromCache();
                return out;
            } 
            long start = System.currentTimeMillis();
            T value = createIfNotPresent.create();
            stats.readFromDisk(start);
            cache.put(id, value);
            return value;
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:get, put
 
	@Override 
	public Resource transform(HttpServletRequest request, Resource resource, ResourceTransformerChain transformerChain) 
			throws IOException { 
 
		Resource transformed = this.cache.get(resource, Resource.class); 
		if (transformed != null) { 
			if (logger.isTraceEnabled()) { 
				logger.trace("Found match"); 
			} 
			return transformed; 
		} 
 
		transformed = transformerChain.transform(request, resource); 
 
		if (logger.isTraceEnabled()) { 
			logger.trace("Putting transformed resource in cache"); 
		} 
		this.cache.put(resource, transformed); 
 

7
CodeRank
This code example shows how to use the following methods:put
	 * Execute {@link Cache#put(Object, Object)} on the specified {@link Cache} 
	 * and invoke the error handler if an exception occurs. 
	 */ 
	protected void doPut(Cache cache, Object key, Object result) {
		try { 
			cache.put(key, result);
		} 
		catch (RuntimeException e) {
			getErrorHandler().handleCachePutError(e, cache, key, result);
		} 
	} 
 
	/** 
	 * Execute {@link Cache#evict(Object)} on the specified {@link Cache} and 
	 * invoke the error handler if an exception occurs. 
	 */ 
	protected void doEvict(Cache cache, Object key) {
		try { 
			cache.evict(key);
		} 
6
CodeRank
This code example shows how to use the following methods:getIfPresent, put
    @Override 
    public Long getSchemaId(final String schemaName, final StandardTitanTx tx) {
        ConcurrentMap<String,Long> types = typeNames;
        Long id;
        if (types==null) {
            id = typeNamesBackup.getIfPresent(schemaName);
            if (id==null) {
                id = retriever.retrieveSchemaByName(schemaName, tx);
                if (id!=null) { //only cache if type exists
                    typeNamesBackup.put(schemaName,id);
                } 
            } 
        } else { 
            id = types.get(schemaName);
            if (id==null) { //Retrieve it
                if (types.size()> maxCachedTypes) {
                    /* Safe guard against the concurrent hash map growing to large - this would be a VERY rare event 
                    as it only happens for graph databases with thousands of types. 
                     */ 
                    typeNames = null;
7
CodeRank
This code example shows how to use the following methods:get, put
	@Override 
	protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath, 
			List<? extends Resource> locations, ResourceResolverChain chain) { 
 
		String key = RESOLVED_RESOURCE_CACHE_KEY_PREFIX + requestPath; 
		Resource resource = this.cache.get(key, Resource.class); 
 
		if (resource != null) { 
			if (logger.isTraceEnabled()) { 
				logger.trace("Found match"); 
			} 
			return resource; 
		} 
 
		resource = chain.resolveResource(request, requestPath, locations); 
		if (resource != null) { 
			if (logger.isTraceEnabled()) { 
				logger.trace("Putting resolved resource in cache"); 
			} 
			this.cache.put(key, resource); 

6
CodeRank
This code example shows how to use the following methods:put
    } 
 
    @Override 
    public void put(QueryParserSettings queryString, Query query) {
        if (queryString.isCacheable()) {
            cache.put(queryString, query);
        } 
    } 
 
    @Override 
    public void clear() { 
        cache.invalidateAll(); 
    } 
 
    @Override 
    public void close() throws ElasticsearchException { 
        cache.invalidateAll(); 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getIfPresent, put
            throw e.getTargetException();
        } 
    } 
 
    private synchronized Map<List<?>, Object> getCache(final Method m) {
        Map<List<?>, Object> cache = caches.getIfPresent(m);
        if (cache == null) { 
            cache = Collections.synchronizedMap(new HashMap<List<?>, Object>());
            caches.put(m, cache);
        } 
        return cache; 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:put
        if (!cachedFile.isFile()) {
            // Has previously been added to the cache directory 
            GFileUtils.copyFile(source, cachedFile);
        } 
        FileInfo fileInfo = new FileInfo(lastModified, length, hashValue, cachedFile);
        cachedFiles.put(source, fileInfo);
        return fileInfo;
    } 
 
    private static class FileInfo { 
        final long lastModified;
        final long length;
        final HashValue hashValue;
        final File cachedFile;
 
        private FileInfo(long lastModified, long length, HashValue hashValue, File cachedFile) {
            this.lastModified = lastModified;
            this.length = length;
            this.hashValue = hashValue;
            this.cachedFile = cachedFile;
6
CodeRank
This code example shows how to use the following methods:getIfPresent, put
		return parser.getDataVersion();
	} 
 
	@Override 
	public ReadableUserAgent parse(final String userAgentString) {
		ReadableUserAgent result = cache.getIfPresent(userAgentString);
		if (result == null) {
			result = parser.parse(userAgentString);
			cache.put(userAgentString, result);
		} 
		return result;
	} 
 
	@Override 
	public void shutdown() { 
		parser.shutdown();
	} 
 
} 
6
CodeRank
put Method Overview
Associates value with key in this cache.
See Code Examples for other Guava Cache Methods: