@@ -51,7 +51,11 @@ public static <Key, Value> LRUCache<Key, Value> usingLoader(final Function<Key,
5151 }
5252
5353 public static <Key , Value > LRUCache <Key , Value > usingLoader (final Function <Key , Value > loader , final RemovalListener <Key , Value > listener , final long maximumSize , final long expireDuration ) {
54- return new LRUCache <>(loader , listener , maximumSize , expireDuration );
54+ return usingLoader (loader , listener , maximumSize , expireDuration , true );
55+ }
56+
57+ public static <Key , Value > LRUCache <Key , Value > usingLoader (final Function <Key , Value > loader , final RemovalListener <Key , Value > listener , final long maximumSize , final long expireDuration , boolean expireAfterAccess ) {
58+ return new LRUCache <>(loader , listener , maximumSize , expireDuration , expireAfterAccess );
5559 }
5660
5761 public static <Key , Value > LRUCache <Key , Value > build () {
@@ -71,12 +75,16 @@ public static <Key, Value> LRUCache<Key, Value> build(final RemovalListener<Key,
7175 }
7276
7377 public static <Key , Value > LRUCache <Key , Value > build (final RemovalListener <Key , Value > listener , final long maximumSize , final long expireDuration ) {
74- return new LRUCache <>(null , listener , maximumSize , expireDuration );
78+ return build (listener , maximumSize , expireDuration , true );
79+ }
80+
81+ public static <Key , Value > LRUCache <Key , Value > build (final RemovalListener <Key , Value > listener , final long maximumSize , final long expireDuration , boolean expireAfterAccess ) {
82+ return new LRUCache <>(null , listener , maximumSize , expireDuration , expireAfterAccess );
7583 }
7684
7785 private final Cache <Key , Value > delegate ;
7886
79- private LRUCache (final Function <Key , Value > loader , final RemovalListener <Key , Value > listener , final long maximumSize , final long expireDuration ) {
87+ private LRUCache (final Function <Key , Value > loader , final RemovalListener <Key , Value > listener , final long maximumSize , final long expireDuration , boolean expireAfterAccess ) {
8088 final CacheBuilder <Object , Object > builder = CacheBuilder .newBuilder ();
8189 if (listener != null ) {
8290 builder .removalListener (new RemovalListener <Key , Value >() {
@@ -93,7 +101,12 @@ public void onRemoval(final RemovalNotification<Key, Value> notification) {
93101 builder .maximumSize (maximumSize );
94102 }
95103 if (expireDuration > 0 ) {
96- builder .expireAfterAccess (expireDuration , TimeUnit .MILLISECONDS );
104+ if (expireAfterAccess ) {
105+ builder .expireAfterAccess (expireDuration , TimeUnit .MILLISECONDS );
106+ }
107+ else {
108+ builder .expireAfterWrite (expireDuration , TimeUnit .MILLISECONDS );
109+ }
97110 }
98111 if (loader != null ) {
99112 delegate = builder .build (new CacheLoader <Key , Value >() {
0 commit comments