All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.xwiki.cache.eviction.EntryEvictionConfiguration Maven / Gradle / Ivy

There is a newer version: 16.10.0-rc-1
Show newest version
/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.cache.eviction;

import java.util.HashMap;

/**
 * This configuration class is used to add constraints in the configuration of the cache to create.
 * 

* * CacheFactory factory = (CacheFactory) getComponentManager().lookup(CacheFactory.class, this.roleHint); * * CacheConfiguration conf = new CacheConfiguration(); * LRUEvictionConfiguration lec = new LRUEvictionConfiguration(); * lec.setMaxEntries(1); * conf.put(LRUEvictionConfiguration.CONFIGURATIONID, lec); * * * @version $Id: 8c63261a8d7b04a568a0bbf424f129bb3a68426e $ */ public class EntryEvictionConfiguration extends HashMap { /** * The key use to access eviction configuration in the {@link org.xwiki.cache.config.CacheConfiguration}. */ public static final String CONFIGURATIONID = "eviction"; /** * @see #getTimeToLive() */ public static final String TIMETOLIVE_ID = "timetolive"; /** * The ordering/storing algorithm used by the cache. * * @version $Id: 8c63261a8d7b04a568a0bbf424f129bb3a68426e $ */ public enum Algorithm { /** * Unlimited cache. Depends of the implementation own limitations. *

* No specific configuration. */ NONE, /** * Evicts the least recently used entry when thresholds are hit. *

* Support maxentries property. See {@link LRUEvictionConfiguration}. */ LRU } /** * The ordering/storing algorithm used by the cache. */ private Algorithm mode; /** * @param mode the ordering/storing algorithm used by the cache. */ public void setAlgorithm(Algorithm mode) { this.mode = mode; } /** * @return the ordering/storing algorithm used by the cache. */ public Algorithm getAlgorithm() { return mode; } /** * @param timeToLive see {@link #getTimeToLive()} */ public void setTimeToLive(int timeToLive) { put(TIMETOLIVE_ID, timeToLive); } /** * @return the time a cache entry will continue to stay in the cache after being last accessed, in seconds. When * the time is reached, the entry is expired and removed from the cache. In addition, when the cache * reaches its maximum number of entries, the defined eviction algorithm is used (e.g. LRU) and thus an * entry can stay less time in the cache than its maximum defined time. */ public int getTimeToLive() { Object obj = get(TIMETOLIVE_ID); return obj == null ? 0 : (Integer) get(TIMETOLIVE_ID); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy