1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.cache.eviction

File EntryEvictionConfiguration.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
5
4
2
112
30
5
1
1.25
2
1.25

Classes

Class Line # Actions
EntryEvictionConfiguration 38 5 0% 5 0
1.0100%
EntryEvictionConfiguration.Algorithm 55 0 - 0 0
-1.0 -
 

Contributing tests

This file is covered by 161 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.cache.eviction;
21   
22    import java.util.HashMap;
23   
24    /**
25    * This configuration class is used to add constraints in the configuration of the cache to create.
26    * <p>
27    * <code>
28    * CacheFactory factory = (CacheFactory) getComponentManager().lookup(CacheFactory.class, this.roleHint);
29    *
30    * CacheConfiguration conf = new CacheConfiguration();
31    * LRUEvictionConfiguration lec = new LRUEvictionConfiguration();
32    * lec.setMaxEntries(1);
33    * conf.put(LRUEvictionConfiguration.CONFIGURATIONID, lec);
34    * </code>
35    *
36    * @version $Id: 8c63261a8d7b04a568a0bbf424f129bb3a68426e $
37    */
 
38    public class EntryEvictionConfiguration extends HashMap<String, Object>
39    {
40    /**
41    * The key use to access eviction configuration in the {@link org.xwiki.cache.config.CacheConfiguration}.
42    */
43    public static final String CONFIGURATIONID = "eviction";
44   
45    /**
46    * @see #getTimeToLive()
47    */
48    public static final String TIMETOLIVE_ID = "timetolive";
49   
50    /**
51    * The ordering/storing algorithm used by the cache.
52    *
53    * @version $Id: 8c63261a8d7b04a568a0bbf424f129bb3a68426e $
54    */
 
55    public enum Algorithm
56    {
57    /**
58    * Unlimited cache. Depends of the implementation own limitations.
59    * <p>
60    * No specific configuration.
61    */
62    NONE,
63    /**
64    * Evicts the least recently used entry when thresholds are hit.
65    * <p>
66    * Support <code>maxentries</code> property. See {@link LRUEvictionConfiguration}.
67    */
68    LRU
69    }
70   
71    /**
72    * The ordering/storing algorithm used by the cache.
73    */
74    private Algorithm mode;
75   
76    /**
77    * @param mode the ordering/storing algorithm used by the cache.
78    */
 
79  730 toggle public void setAlgorithm(Algorithm mode)
80    {
81  730 this.mode = mode;
82    }
83   
84    /**
85    * @return the ordering/storing algorithm used by the cache.
86    */
 
87  468 toggle public Algorithm getAlgorithm()
88    {
89  468 return mode;
90    }
91   
92    /**
93    * @param timeToLive see {@link #getTimeToLive()}
94    */
 
95  109 toggle public void setTimeToLive(int timeToLive)
96    {
97  109 put(TIMETOLIVE_ID, timeToLive);
98    }
99   
100    /**
101    * @return the time a cache entry will continue to stay in the cache after being last accessed, in seconds. When
102    * the time is reached, the entry is expired and removed from the cache. In addition, when the cache
103    * reaches its maximum number of entries, the defined eviction algorithm is used (e.g. LRU) and thus an
104    * entry can stay less time in the cache than its maximum defined time.
105    */
 
106  672 toggle public int getTimeToLive()
107    {
108  672 Object obj = get(TIMETOLIVE_ID);
109   
110  672 return obj == null ? 0 : (Integer) get(TIMETOLIVE_ID);
111    }
112    }