Open feivur opened 4 years ago
I added cache entry creation time param to Snapshot. With this simple feature we can make expiration cache. Example:
private Bitmap getExpired( String key, long expire, TimeUnit timeUnit ) { Bitmap bitmap = null; try ( DiskLruCache.Snapshot snapshot = mDiskCache.get( key ) ) { if ( snapshot == null ) return bitmap; long expiredTime = new Date().getTime() - timeUnit.toMillis( expire ); if ( expire > 0 && snapshot.getCreatedTime() < expiredTime ) return null; final InputStream in = snapshot.getInputStream( 0 ); if ( in != null ) { final BufferedInputStream buffIn = new BufferedInputStream( in, IO_BUFFER_SIZE ); bitmap = BitmapFactory.decodeStream( buffIn ); } } catch ( IOException e ) { e.printStackTrace(); } return bitmap; }
I added cache entry creation time param to Snapshot. With this simple feature we can make expiration cache. Example:
private Bitmap getExpired( String key, long expire, TimeUnit timeUnit ) { Bitmap bitmap = null; try ( DiskLruCache.Snapshot snapshot = mDiskCache.get( key ) ) { if ( snapshot == null ) return bitmap; long expiredTime = new Date().getTime() - timeUnit.toMillis( expire ); if ( expire > 0 && snapshot.getCreatedTime() < expiredTime ) return null; final InputStream in = snapshot.getInputStream( 0 ); if ( in != null ) { final BufferedInputStream buffIn = new BufferedInputStream( in, IO_BUFFER_SIZE ); bitmap = BitmapFactory.decodeStream( buffIn ); } } catch ( IOException e ) { e.printStackTrace(); } return bitmap; }