Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Conversation

@feivur
Copy link

@feivur feivur commented Mar 2, 2020

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; }

@Christo0852
Copy link

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; }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants