📄 cache.java
字号:
/** * $RCSfile: Cache.java,v $ * $Revision: 1.5 $ * $Date: 2002/05/10 21:53:20 $ * * Copyright (C) 1999-2002 CoolServlets, Inc. All rights reserved. * * This software is the proprietary information of CoolServlets, Inc. * Use is subject to license terms. */package com.jivesoftware.util;/** * General purpose cache. It stores objects associated with unique keys in * memory for fast access. All keys and values added to the cache must * implement the Serializable interface. Values may implement the Cacheable * interface, which allows the cache to determine object size much more quickly. * These restrictions allow a cache to never grow larger than a specified number * of bytes and to optionally be distributed over a cluster of servers.<p> * * If the cache does grow too large, objects will be removed such that those * that are accessed least frequently are removed first. Because expiration * happens automatically, the cache makes <b>no</b> gaurantee as to how long * an object will remain in cache after it is put in.<p> * * Optionally, a maximum lifetime for all objects can be specified. In that * case, objects will be deleted from cache after that amount of time, even * if they are frequently accessed. This feature is useful if objects put in * cache represent data that should be periodically refreshed; for example, * information from a database.<p> * * All cache operations are thread safe.<p> * * @see Cacheable * @author Matt Tucker */public interface Cache extends java.util.Map { /** * Returns the name of the cache. * * @return the name of the cache. */ String getName(); /** * Returns the maximum size of the cache in bytes. If the cache grows * larger than the max size, the least frequently used items will be removed. * * @return the maximum size of the cache in bytes. */ int getMaxCacheSize(); /** * Sets the maximum size of the cache in bytes. If the cache grows * larger than the max size, the least frequently used items will be removed. * * @param maxSize the maximum size of the cache in bytes. */ void setMaxCacheSize(int maxSize); /** * Returns the maximum number of milleseconds that any object can live * in cache. Once the specified number of milleseconds passes, the object * will be automatically expried from cache. If the max lifetime is set * to -1, then objects never expire. * * @return the maximum number of milleseconds before objects are expired. */ long getMaxLifetime(); /** * Sets the maximum number of milleseconds that any object can live * in cache. Once the specified number of milleseconds passes, the object * will be automatically expried from cache. If the max lifetime is set * to -1, then objects never expire. * * @param maxLifetime the maximum number of milleseconds before objects are expired. */ void setMaxLifetime(long maxLifetime); /** * Returns the size of the cache contents in bytes. This value is only a * rough approximation, so cache users should expect that actual VM * memory used by the cache could be significantly higher than the value * reported by this method. * * @return the size of the cache contents in bytes. */ int getCacheSize(); /** * Returns the number of cache hits. A cache hit occurs every * time the get method is called and the cache contains the requested * object.<p> * * Keeping track of cache hits and misses lets one measure how efficient * the cache is; the higher the percentage of hits, the more efficient. * * @return the number of cache hits. */ long getCacheHits(); /** * Returns the number of cache misses. A cache miss occurs every * time the get method is called and the cache does not contain the * requested object.<p> * * Keeping track of cache hits and misses lets one measure how efficient * the cache is; the higher the percentage of hits, the more efficient. * * @return the number of cache hits. */ long getCacheMisses();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -