Cache get - 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 get method.

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:get
	 * miss in case of error. 
	 * @see Cache#get(Object) 
	 */ 
	protected Cache.ValueWrapper doGet(Cache cache, Object key) {
		try { 
			return cache.get(key);
		} 
		catch (RuntimeException e) {
			getErrorHandler().handleCacheGetError(e, cache, key);
			return null; // If the exception is handled, return a cache miss 
		} 
	} 
 
	/** 
	 * 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);
6
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
    protected void onPostExecute(Bitmap bitmap) {
 
        if (bitmap != null) {
            view.setVisibility(View.VISIBLE);
            view.setImageBitmap(bitmap);
            lruCache.put(data, bitmap);
 
        } else { 
            view.setImageDrawable(new ColorDrawable(Color.TRANSPARENT));
        } 
 
    } 
 
 
} 
6
CodeRank
This code example shows how to use the following methods:get, put, remove
	} 
 
	public Bitmap getBitmap(long key) {
		Bitmap bm = getFolderBitmap(key);
		if (bm != null) return bm;
		return mContentCache.get(key);
	} 
	 
	public void clearAll() { 
		clearContent(); 
		clearFolder(); 
	} 
	 
	public void clearContent() { 
		mContentCache.evictAll();
	} 
	 
	public void clearFolder() { 
		mFolderCache.evictAll();
	} 

7
CodeRank
This code example shows how to use the following methods:get
     * If only wants values that are not expired, use {@link #get(Object)} instead. 
     * 
     * @param key the key to look up 
     */ 
    public CachedValue<V> getCachedValue(K key) {
        return mCache.get(key);
    } 
 
    /** 
     * Returns the value for the given key, or null if no value exists. 
     * <p> 
     * When using this method, it is not possible to determine whether the value is expired or not. 
     * Use {@link #getCachedValue(Object)} to achieve that instead. However, if using 
     * {@link #getCachedValue(Object)} to determine if an item is expired, one should use the item 
     * within the {@link CachedValue} and not call {@link #getPossiblyExpired(Object)} to get the 
     * value afterwards, since that is not guaranteed to return the same value or that the newly 
     * returned value is in the same state. 
     * 
     * @param key the key to look up 
     */ 
6
CodeRank
This code example shows how to use the following methods:get, put
        mPadding      = context.getResources().getDimensionPixelOffset(R.dimen.marker_padding  );
    } 
 
    public Bitmap get(String color, String route) {
        String key = color+"_"+route;
        Bitmap bitmap = mCache.get(key);
        if (bitmap != null) {
            return bitmap;
        } 
        bitmap = render(Color.parseColor(color), route);
        mCache.put(key, bitmap);
        return bitmap;
    } 
 
    private Bitmap render(int color, String text) {
        TextPaint textPaint = new TextPaint();
        textPaint.setColor(Color.WHITE);
        textPaint.setStyle(Paint.Style.FILL);
        textPaint.setAntiAlias(true);
        textPaint.setTextSize(mTextSize);
5
CodeRank
This code example shows how to use the following methods:get, put
 
	} 
 
	public void addBitmapToMemoryCache(String key, Bitmap bitmap) { 
		if (getBitmapFromMemCache(key) == null) { 
			mMemoryCache.put(key, bitmap); 
		} 
	} 
 
	public Bitmap getBitmapFromMemCache(String key) { 
		return (Bitmap) mMemoryCache.get(key); 
	} 
 
	public Bitmap decodeSampledBitmapFromUri(String path, int reqWidth, 
			int reqHeight) { 
		Bitmap bm = null; 
 
		// First decode with inJustDecodeBounds=true to check dimensions 
		final BitmapFactory.Options options = new BitmapFactory.Options(); 
		options.inJustDecodeBounds = true; 
4
CodeRank
This code example shows how to use the following methods:put
            JSONObject act = new JSONObject(m_cursor.getString(0));
            JSONObject obj = act.optJSONObject("object");
            if(obj != null) {
                String id = obj.optString("id");
                if(id != null) {
                    m_objectPositions.put(id, position);
                } 
            } 
 
            act.put("_replies", m_cursor.getInt(1));
            act.put("_likes",   m_cursor.getInt(2));
            act.put("_shares",  m_cursor.getInt(3));
 
            return act;
        } catch(JSONException e) {
            throw new RuntimeException(e);
        } 
	} 
 
	private static String getImage(JSONObject obj) {
5
CodeRank
This code example shows how to use the following methods:get, put
	 * @param imageUrl URL of bitmap 
	 * @return Loaded bitmap, or <code>null</code> 
	 */ 
	public Bitmap getImage(String imageUrl) {
		// Bitmap cached in memory? 
		Bitmap cachedBitmap = memoryCache.get(imageUrl);
		if (cachedBitmap != null) {
			return cachedBitmap;
		} 
		 
		// In file cache? 
		InputStream cachedImage = fileCache.getStream(imageUrl);
		if (cachedImage != null) {
			Bitmap bitmap = BitmapFactory.decodeStream(cachedImage);
			if (bitmap != null) {
				memoryCache.put(imageUrl, bitmap);
			} 
			try { 
				cachedImage.close();
			} catch (IOException e) {

4
CodeRank
get Method Overview
Returns the value associated with key in this cache, obtaining that value from valueLoader if necessary.
See Code Examples for other Guava Cache Methods: