1 /**
2  *  Copyright Terracotta, Inc.
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */

16
17 package net.sf.ehcache.store;
18
19 import net.sf.ehcache.Element;
20
21
22 /**
23  * Contains common LFU policy code for use between the LfuMemoryStore and the DiskStore, which also
24  * uses an LfuPolicy for evictions.
25  *
26  * @author Greg Luck
27  * @version $Id: LruPolicy.java 5631 2012-05-10 08:31:33Z teck $
28  */

29 public class LruPolicy extends AbstractPolicy {
30
31     /**
32      * The name of this policy as a string literal
33      */

34      public static final String NAME = "LRU";
35
36     /**
37      * @return the name of the Policy. Inbuilt examples are LRU, LFU and FIFO.
38      */

39     public String getName() {
40         return NAME;
41     }
42
43     /**
44      * Compares the desirableness for eviction of two elements
45      *
46      * Compares hit counts. If both zero,
47      *
48      * @param element1 the element to compare against
49      * @param element2 the element to compare
50      * @return true if the second element is preferable to the first element for ths policy
51      */

52     public boolean compare(Element element1, Element element2) {
53         return element2.getLastAccessTime() < element1.getLastAccessTime();
54
55     }
56
57 }
58