亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? cache.java

?? oscache-2.4.1-full
?? JAVA
?? 第 1 頁 / 共 3 頁
字號:
/*
 * Copyright (c) 2002-2003 by OpenSymphony
 * All rights reserved.
 */
package com.opensymphony.oscache.base;

import com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache;
import com.opensymphony.oscache.base.algorithm.LRUCache;
import com.opensymphony.oscache.base.algorithm.UnlimitedCache;
import com.opensymphony.oscache.base.events.*;
import com.opensymphony.oscache.base.persistence.PersistenceListener;
import com.opensymphony.oscache.util.FastCronParser;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.Serializable;

import java.text.ParseException;

import java.util.*;

import javax.swing.event.EventListenerList;

/**
 * Provides an interface to the cache itself. Creating an instance of this class
 * will create a cache that behaves according to its construction parameters.
 * The public API provides methods to manage objects in the cache and configure
 * any cache event listeners.
 *
 * @version        $Revision: 468 $
 * @author <a href="mailto:mike@atlassian.com">Mike Cannon-Brookes</a>
 * @author <a href="mailto:tgochenour@peregrine.com">Todd Gochenour</a>
 * @author <a href="mailto:fbeauregard@pyxis-tech.com">Francois Beauregard</a>
 * @author <a href="&#109;a&#105;&#108;&#116;&#111;:chris&#64;swebtec.&#99;&#111;&#109;">Chris Miller</a>
 */
public class Cache implements Serializable {
    /**
     * An event that origininated from within another event.
     */
    public static final String NESTED_EVENT = "NESTED";
    private static transient final Log log = LogFactory.getLog(Cache.class);

    /**
     * A list of all registered event listeners for this cache.
     */
    protected EventListenerList listenerList = new EventListenerList();

    /**
     * The actual cache map. This is where the cached objects are held.
     */
    private AbstractConcurrentReadCache cacheMap = null;

    /**
     * Date of last complete cache flush.
     */
    private Date flushDateTime = null;

    /**
     * A map that holds keys of cache entries that are currently being built, and EntryUpdateState instance as values. This is used to coordinate threads
     * that modify/access a same key in concurrence.
     * 
     * The cache checks against this map when a stale entry is requested, or a cache miss is observed.
     * 
     * If the requested key is in here, we know the entry is currently being
     * built by another thread and hence we can either block and wait or serve
     * the stale entry (depending on whether cache blocking is enabled or not).
     * <p>
     * To avoid data races, values in this map should remain present during the whole time distinct threads deal with the
     * same key. We implement this using explicit reference counting in the EntryUpdateState instance, to be able to clean up
     * the map once all threads have declared they are done accessing/updating a given key.
     * 
     * It is not possible to locate this into the CacheEntry because this would require to have a CacheEntry instance for all cache misses, and
     * may therefore generate a memory leak. More over, the CacheEntry instance may not be hold in memory in the case no
     * memory cache is configured.
     */
    private Map updateStates = new HashMap();

    /**
     * Indicates whether the cache blocks requests until new content has
     * been generated or just serves stale content instead.
     */
    private boolean blocking = false;

    /**
     * Create a new Cache
     *
     * @param useMemoryCaching Specify if the memory caching is going to be used
     * @param unlimitedDiskCache Specify if the disk caching is unlimited
     * @param overflowPersistence Specify if the persistent cache is used in overflow only mode
     */
    public Cache(boolean useMemoryCaching, boolean unlimitedDiskCache, boolean overflowPersistence) {
        this(useMemoryCaching, unlimitedDiskCache, overflowPersistence, false, null, 0);
    }

    /**
     * Create a new Cache.
     *
     * If a valid algorithm class is specified, it will be used for this cache.
     * Otherwise if a capacity is specified, it will use LRUCache.
     * If no algorithm or capacity is specified UnlimitedCache is used.
     *
     * @see com.opensymphony.oscache.base.algorithm.LRUCache
     * @see com.opensymphony.oscache.base.algorithm.UnlimitedCache
     * @param useMemoryCaching Specify if the memory caching is going to be used
     * @param unlimitedDiskCache Specify if the disk caching is unlimited
     * @param overflowPersistence Specify if the persistent cache is used in overflow only mode
     * @param blocking This parameter takes effect when a cache entry has
     * just expired and several simultaneous requests try to retrieve it. While
     * one request is rebuilding the content, the other requests will either
     * block and wait for the new content (<code>blocking == true</code>) or
     * instead receive a copy of the stale content so they don't have to wait
     * (<code>blocking == false</code>). the default is <code>false</code>,
     * which provides better performance but at the expense of slightly stale
     * data being served.
     * @param algorithmClass The class implementing the desired algorithm
     * @param capacity The capacity
     */
    public Cache(boolean useMemoryCaching, boolean unlimitedDiskCache, boolean overflowPersistence, boolean blocking, String algorithmClass, int capacity) {
        // Instantiate the algo class if valid
        if (((algorithmClass != null) && (algorithmClass.length() > 0)) && (capacity > 0)) {
            try {
                cacheMap = (AbstractConcurrentReadCache) Class.forName(algorithmClass).newInstance();
                cacheMap.setMaxEntries(capacity);
            } catch (Exception e) {
                log.error("Invalid class name for cache algorithm class. " + e.toString());
            }
        }

        if (cacheMap == null) {
            // If we have a capacity, use LRU cache otherwise use unlimited Cache
            if (capacity > 0) {
                cacheMap = new LRUCache(capacity);
            } else {
                cacheMap = new UnlimitedCache();
            }
        }

        cacheMap.setUnlimitedDiskCache(unlimitedDiskCache);
        cacheMap.setOverflowPersistence(overflowPersistence);
        cacheMap.setMemoryCaching(useMemoryCaching);

        this.blocking = blocking;
    }
    
    /**
     * @return the maximum number of items to cache can hold.
     */
    public int getCapacity() {
        return cacheMap.getMaxEntries();
    }

    /**
     * Allows the capacity of the cache to be altered dynamically. Note that
     * some cache implementations may choose to ignore this setting (eg the
     * {@link UnlimitedCache} ignores this call).
     *
     * @param capacity the maximum number of items to hold in the cache.
     */
    public void setCapacity(int capacity) {
        cacheMap.setMaxEntries(capacity);
    }

    /**
     * Checks if the cache was flushed more recently than the CacheEntry provided.
     * Used to determine whether to refresh the particular CacheEntry.
     *
     * @param cacheEntry The cache entry which we're seeing whether to refresh
     * @return Whether or not the cache has been flushed more recently than this cache entry was updated.
     */
    public boolean isFlushed(CacheEntry cacheEntry) {
        if (flushDateTime != null) {
            final long lastUpdate = cacheEntry.getLastUpdate();
            final long flushTime = flushDateTime.getTime();

            // CACHE-241: check flushDateTime with current time also
            return (flushTime <= System.currentTimeMillis()) && (flushTime >= lastUpdate);
        } else {
            return false;
        }
    }

    /**
     * Retrieve an object from the cache specifying its key.
     *
     * @param key             Key of the object in the cache.
     *
     * @return The object from cache
     *
     * @throws NeedsRefreshException Thrown when the object either
     * doesn't exist, or exists but is stale. When this exception occurs,
     * the CacheEntry corresponding to the supplied key will be locked
     * and other threads requesting this entry will potentially be blocked
     * until the caller repopulates the cache. If the caller choses not
     * to repopulate the cache, they <em>must</em> instead call
     * {@link #cancelUpdate(String)}.
     */
    public Object getFromCache(String key) throws NeedsRefreshException {
        return getFromCache(key, CacheEntry.INDEFINITE_EXPIRY, null);
    }

    /**
     * Retrieve an object from the cache specifying its key.
     *
     * @param key             Key of the object in the cache.
     * @param refreshPeriod   How long before the object needs refresh. To
     * allow the object to stay in the cache indefinitely, supply a value
     * of {@link CacheEntry#INDEFINITE_EXPIRY}.
     *
     * @return The object from cache
     *
     * @throws NeedsRefreshException Thrown when the object either
     * doesn't exist, or exists but is stale. When this exception occurs,
     * the CacheEntry corresponding to the supplied key will be locked
     * and other threads requesting this entry will potentially be blocked
     * until the caller repopulates the cache. If the caller choses not
     * to repopulate the cache, they <em>must</em> instead call
     * {@link #cancelUpdate(String)}.
     */
    public Object getFromCache(String key, int refreshPeriod) throws NeedsRefreshException {
        return getFromCache(key, refreshPeriod, null);
    }

    /**
     * Retrieve an object from the cache specifying its key.
     *
     * @param key             Key of the object in the cache.
     * @param refreshPeriod   How long before the object needs refresh. To
     * allow the object to stay in the cache indefinitely, supply a value
     * of {@link CacheEntry#INDEFINITE_EXPIRY}.
     * @param cronExpiry      A cron expression that specifies fixed date(s)
     *                        and/or time(s) that this cache entry should
     *                        expire on.
     *
     * @return The object from cache
     *
     * @throws NeedsRefreshException Thrown when the object either
     * doesn't exist, or exists but is stale. When this exception occurs,
     * the CacheEntry corresponding to the supplied key will be locked
     * and other threads requesting this entry will potentially be blocked
     * until the caller repopulates the cache. If the caller choses not
     * to repopulate the cache, they <em>must</em> instead call
     * {@link #cancelUpdate(String)}.
     */
    public Object getFromCache(String key, int refreshPeriod, String cronExpiry) throws NeedsRefreshException {
        CacheEntry cacheEntry = this.getCacheEntry(key, null, null);

        Object content = cacheEntry.getContent();
        CacheMapAccessEventType accessEventType = CacheMapAccessEventType.HIT;

        boolean reload = false;

        // Check if this entry has expired or has not yet been added to the cache. If
        // so, we need to decide whether to block, serve stale content or throw a
        // NeedsRefreshException
        if (this.isStale(cacheEntry, refreshPeriod, cronExpiry)) {

            //Get access to the EntryUpdateState instance and increment the usage count during the potential sleep
            EntryUpdateState updateState = getUpdateState(key);
            try {
                synchronized (updateState) {
                    if (updateState.isAwaitingUpdate() || updateState.isCancelled()) {
                        // No one else is currently updating this entry - grab ownership
                        updateState.startUpdate();
                        
                        if (cacheEntry.isNew()) {
                            accessEventType = CacheMapAccessEventType.MISS;
                        } else {
                            accessEventType = CacheMapAccessEventType.STALE_HIT;
                        }
                    } else if (updateState.isUpdating()) {
                        // Another thread is already updating the cache. We block if this
                        // is a new entry, or blocking mode is enabled. Either putInCache()
                        // or cancelUpdate() can cause this thread to resume.
                        if (cacheEntry.isNew() || blocking) {
                            do {
                                try {
                                    updateState.wait();
                                } catch (InterruptedException e) {
                                }
                            } while (updateState.isUpdating());
                            
                            if (updateState.isCancelled()) {
                                // The updating thread cancelled the update, let this one have a go. 
                                // This increments the usage count for this EntryUpdateState instance
                                updateState.startUpdate();
                                
                                if (cacheEntry.isNew()) {
                                    accessEventType = CacheMapAccessEventType.MISS;
                                } else {
                                    accessEventType = CacheMapAccessEventType.STALE_HIT;
                                }
                            } else if (updateState.isComplete()) {
                                reload = true;
                            } else {
                                log.error("Invalid update state for cache entry " + key);
                            }
                        }
                    } else {
                        reload = true;
                    }
                }
            } finally {
                //Make sure we release the usage count for this EntryUpdateState since we don't use it anymore. If the current thread started the update, then the counter was
                //increased by one in startUpdate()
                releaseUpdateState(updateState, key);
            }
        }

        // If reload is true then another thread must have successfully rebuilt the cache entry
        if (reload) {
            cacheEntry = (CacheEntry) cacheMap.get(key);

            if (cacheEntry != null) {
                content = cacheEntry.getContent();
            } else {
                log.error("Could not reload cache entry after waiting for it to be rebuilt");
            }
        }

        dispatchCacheMapAccessEvent(accessEventType, cacheEntry, null);

        // If we didn't end up getting a hit then we need to throw a NRE
        if (accessEventType != CacheMapAccessEventType.HIT) {
            throw new NeedsRefreshException(content);
        }

        return content;
    }

    /**
     * Set the listener to use for data persistence. Only one
     * <code>PersistenceListener</code> can be configured per cache.
     *
     * @param listener The implementation of a persistance listener
     */
    public void setPersistenceListener(PersistenceListener listener) {
        cacheMap.setPersistenceListener(listener);
    }

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本丰满少妇一区二区三区| 免费黄网站欧美| 99精品热视频| 樱桃国产成人精品视频| 欧美亚洲国产一区在线观看网站| 亚洲一区二区三区视频在线| 91麻豆精品国产91久久久资源速度| 日韩精品一区第一页| 欧美zozozo| 国产精一品亚洲二区在线视频| 欧美极品aⅴ影院| 色综合天天综合网国产成人综合天| 亚洲成人免费视频| 精品欧美乱码久久久久久| 国产在线视频一区二区| 中文字幕一区三区| 欧美日韩午夜精品| 久久99国产精品久久99| 国产精品二区一区二区aⅴ污介绍| 一本到一区二区三区| 日韩精品1区2区3区| 久久久国产精品不卡| 色菇凉天天综合网| 久久99热狠狠色一区二区| 国产精品久久久久久久久免费樱桃| 91视频www| 久久99精品国产.久久久久| 日本成人中文字幕在线视频| 国产亚洲成aⅴ人片在线观看| 色菇凉天天综合网| 国内精品第一页| 亚洲最大成人综合| 久久久另类综合| 欧美老肥妇做.爰bbww| 成人综合婷婷国产精品久久蜜臀| 亚洲国产乱码最新视频| 国产亚洲精品免费| 欧美一区二区三区男人的天堂| 99久久免费国产| 蜜臀av性久久久久蜜臀aⅴ流畅| 中文字幕第一区第二区| 欧美精品在线观看一区二区| av成人免费在线观看| 看电视剧不卡顿的网站| 一区二区三区在线免费| 国产校园另类小说区| 91精品国产91热久久久做人人| 99久久国产综合色|国产精品| 开心九九激情九九欧美日韩精美视频电影| 亚洲女同女同女同女同女同69| 久久综合九色综合欧美就去吻| 欧美精品aⅴ在线视频| 99精品久久免费看蜜臀剧情介绍| 久草中文综合在线| 性感美女极品91精品| 亚洲人成网站影音先锋播放| 久久久国产一区二区三区四区小说| 在线成人小视频| 91福利国产成人精品照片| 成人国产一区二区三区精品| 狠狠色丁香九九婷婷综合五月| 天天影视网天天综合色在线播放| 亚洲色图视频免费播放| 中日韩免费视频中文字幕| 欧美成人性福生活免费看| 欧美精品乱码久久久久久按摩| 91亚洲国产成人精品一区二区三| 国产91精品一区二区| 国产精品一区在线| 国产原创一区二区| 国产精品自拍一区| 国产福利一区在线| 国产精品综合一区二区三区| 国产九九视频一区二区三区| 国产一区二区剧情av在线| 国产真实精品久久二三区| 国产在线一区观看| 国产成人久久精品77777最新版本| 麻豆成人久久精品二区三区小说| 日产国产高清一区二区三区 | 久久影视一区二区| 亚洲精品一线二线三线无人区| 日韩亚洲欧美中文三级| 精品日产卡一卡二卡麻豆| 一区二区三区四区蜜桃| 成人免费在线视频观看| 亚洲乱码中文字幕综合| 亚洲美女免费视频| 亚洲精品高清在线观看| 亚洲aaa精品| 久久66热偷产精品| 国产黄色成人av| 国产 欧美在线| 99v久久综合狠狠综合久久| 色先锋aa成人| 国产一区二区三区四区五区入口| 成人激情视频网站| 色8久久人人97超碰香蕉987| 欧美色电影在线| 欧美大度的电影原声| 中文字幕不卡在线播放| 一区二区三区中文字幕电影| 青青草国产成人av片免费| 国产精品一二三| 99久久婷婷国产综合精品| 欧美最猛性xxxxx直播| 9191久久久久久久久久久| 久久丝袜美腿综合| 亚洲精品视频在线观看网站| 天堂影院一区二区| 国产精品一级片| 欧美这里有精品| 精品播放一区二区| 亚洲欧美一区二区在线观看| 无码av免费一区二区三区试看| 国内精品国产三级国产a久久| 波波电影院一区二区三区| 欧美日韩国产小视频在线观看| 精品国产乱码91久久久久久网站| 国产精品婷婷午夜在线观看| 午夜欧美一区二区三区在线播放| 国内精品免费**视频| 色综合久久88色综合天天免费| 日韩手机在线导航| 亚洲欧美成aⅴ人在线观看| 久久精品国产99国产| 91久久一区二区| 国产日韩欧美精品在线| 日韩中文字幕1| 久久综合色播五月| 亚洲成人免费视频| jlzzjlzz国产精品久久| 日韩欧美一区二区在线视频| 亚洲男人天堂av| 国产精品一区二区免费不卡| 欧美日本在线播放| 综合分类小说区另类春色亚洲小说欧美 | 久久久久久一二三区| 伊人色综合久久天天人手人婷| 国产精品1区2区| 日韩精品一区二区三区在线观看 | 2022国产精品视频| 亚洲一区国产视频| 成人三级伦理片| 久久综合色一综合色88| 免费观看在线综合| 欧美久久久久久蜜桃| 亚洲免费毛片网站| av亚洲精华国产精华| 国产亚洲欧美日韩在线一区| 精品一区二区免费视频| 欧美一级黄色片| 日韩av一级片| 7777精品伊人久久久大香线蕉的 | 亚洲电影激情视频网站| 99视频在线观看一区三区| 欧美国产日本韩| 国产成人久久精品77777最新版本 国产成人鲁色资源国产91色综 | 欧美午夜电影网| 一卡二卡欧美日韩| 色欧美乱欧美15图片| 亚洲女人的天堂| 国产成人精品免费网站| 国产欧美日韩在线| 豆国产96在线|亚洲| 欧美成人a∨高清免费观看| 亚洲国产裸拍裸体视频在线观看乱了| 一本色道久久综合狠狠躁的推荐| 亚洲国产精品t66y| 国产91丝袜在线观看| 久久夜色精品一区| 国产成a人无v码亚洲福利| 国产三区在线成人av| 国产成人精品网址| 中文字幕av不卡| 91免费观看国产| 亚洲综合在线免费观看| 欧美日韩成人一区| 日韩av一区二| www国产成人| 成人app网站| 亚洲女厕所小便bbb| 一本久久a久久精品亚洲| 一区二区久久久| 欧美一级xxx| 国产成人精品www牛牛影视| 国产精品网站在线观看| 日本乱人伦aⅴ精品| 亚洲午夜三级在线| 日韩一级大片在线| 国产精品亚洲专一区二区三区| 日韩一区在线播放| 欧美久久一二区| 日本va欧美va精品发布| 久久无码av三级| 色综合久久久久综合体| 亚洲一区二区三区四区五区黄| 欧美一区二区三区四区久久| 国产剧情一区二区| 亚洲美女屁股眼交3|