package com.bypassmobile.octo.image;


import android.graphics.Bitmap;

import com.squareup.picasso.Cache;

import java.util.LinkedHashMap;
import java.util.Map;

public class ImageCache implements Cache{

    private Map<String,Bitmap> cacheMap = new LinkedHashMap<String,Bitmap>();

    @Override
    public Bitmap get(String stringResource) {
        return cacheMap.get(stringResource);
    }

    @Override
    public void set(String stringResource, Bitmap bitmap) {
        cacheMap.put(stringResource,bitmap);
    }

    @Override
    public int size() {
        return cacheMap.size();
    }

    @Override
    public int maxSize() {
        return Integer.MAX_VALUE;
    }

    @Override
    public void clear() {
        cacheMap.clear();
    }
}

@@ -199,16 +199,488 @@
 Cache%7B%0A%0A
+    //BitmapStamp is a simple datastructure that lets us keep track of the time we downloaded an image%0A    //if when we go to retrieve an image it has been too long, we will just discard the result%0A    private static class BitmapStamp%7B%0A        Bitmap mBitmap;%0A        long mTimestamp;%0A%0A        public BitmapStamp(Bitmap bitmap, long currentTime)%7B%0A            mBitmap = bitmap;%0A            mTimestamp = currentTime;%0A        %7D%0A    %7D%0A    private long TIMEOUT_TIME = 3600000;%0A
     priv
@@ -700,16 +700,21 @@
 g,Bitmap
+Stamp
 %3E cacheM
@@ -736,29 +736,16 @@
 HashMap%3C
-String,Bitmap
 %3E();%0A%0A  
@@ -803,38 +803,51 @@
 urce) %7B%0A        
-return
+BitmapStamp stamp =
  cacheMap.get(st
@@ -861,16 +861,195 @@
 ource);%0A
+        if((stamp == null)%7C%7C ((System.currentTimeMillis() - stamp.mTimestamp))%3ETIMEOUT_TIME) %7B%0A            return null;%0A        %7Delse%7B%0A            return stamp.mBitmap;%0A        %7D%0A
     %7D%0A%0A 
@@ -1157,22 +1157,67 @@
 esource,
-bitmap
+new BitmapStamp(bitmap, System.currentTimeMillis())
 );%0A    %7D

add in cache invalidation