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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? cache.java

?? 這是學(xué)習(xí)Java必須讀懂兩套源代碼
?? JAVA
?? 第 1 頁 / 共 2 頁
字號(hào):
     * Sets the maximum size of the cache in bytes. If the cache grows too
     * large, the least frequently used items will automatically be deleted so
     * that the cache size doesn't exceed the maximum.
     *
     * @param maxSize the maximum size of the cache in bytes.
     */
    public void setMaxSize(int maxSize) {
        this.maxSize = maxSize;
        //It's possible that the new max size is smaller than our current cache
        //size. If so, we need to delete infrequently used items.
        cullCache();
    }

    /**
     * Returns the number of objects in the cache.
     *
     * @return the number of objects in the cache.
     */
    public synchronized int getNumElements() {
        return cachedObjectsHash.size();
    }

    /**
     * Adds a new Cacheable object to the cache. The key must be unique.
     *
     * @param key a unique key for the object being put into cache.
     * @param object the Cacheable object to put into cache.
     */
    public synchronized void add(Object key, Cacheable object) {
        //DEBUG
        //System.err.println("Adding object with key " + key + " to hash " + this);

        //Don't add an object with the same key multiple times.
        if (cachedObjectsHash.containsKey(key)) {
            return;
        }
        int objectSize = object.getSize();
        //If the object is bigger than the entire cache, simply don't add it.
        if (objectSize > maxSize * .90) {
            return;
        }
        size += objectSize;
        CacheObject cacheObject = new CacheObject(object, objectSize);
        cachedObjectsHash.put(key, cacheObject);
        //Make an entry into the cache order list.
        LinkedListNode lastAccessedNode = lastAccessedList.addFirst(key);
        //Store the cache order list entry so that we can get back to it
        //during later lookups.
        cacheObject.lastAccessedListNode = lastAccessedNode;
        //Add the object to the age list
        LinkedListNode ageNode = ageList.addFirst(key);
        //We make an explicit call to currentTimeMillis() so that total accuracy
        //of lifetime calculations is better than one second.
        ageNode.timestamp = System.currentTimeMillis();
        cacheObject.ageListNode = ageNode;

        //If cache is too full, remove least used cache entries until it is
        //not too full.
        cullCache();
    }

    /**
     * Gets an object from cache. This method will return null under two
     * conditions:<ul>
     *    <li>The object referenced by the key was never added to cache.
     *    <li>The object referenced by the key has expired from cache.</ul>
     *
     * @param key the unique key of the object to get.
     * @return the Cacheable object corresponding to unique key.
     */
    public synchronized Cacheable get(Object key) {
        //First, clear all entries that have been in cache longer than the
        //maximum defined age.
        deleteExpiredEntries();

        CacheObject cacheObject = (CacheObject)cachedObjectsHash.get(key);
        if (cacheObject == null) {
            //The object didn't exist in cache, so increment cache misses.
            cacheMisses++;
            return null;
        }

        //The object exists in cache, so increment cache hits.
        cacheHits++;

        //Remove the object from it's current place in the cache order list,
        //and re-insert it at the front of the list.
        cacheObject.lastAccessedListNode.remove();
        lastAccessedList.addFirst(cacheObject.lastAccessedListNode);

        return cacheObject.object;
    }

    /**
     * Removes an object from cache.
     *
     * @param key the unique key of the object to remove.
     */
    public synchronized void remove(Object key) {
        //DEBUG
        //System.err.println("Removing object with key: " + key + " from hash " + this);

        CacheObject cacheObject = (CacheObject)cachedObjectsHash.get(key);
        //If the object is not in cache, stop trying to remove it.
        if (cacheObject == null) {
            return;
        }
        //remove from the hash map
        cachedObjectsHash.remove(key);
        //remove from the cache order list
        cacheObject.lastAccessedListNode.remove();
        cacheObject.ageListNode.remove();
        //remove references to linked list nodes
        cacheObject.ageListNode = null;
        cacheObject.lastAccessedListNode = null;
        //removed the object, so subtract its size from the total.
        size -= cacheObject.size;
    }

    /**
     * Clears the cache of all objects. The size of the cache is reset to 0.
     */
    public synchronized void clear() {
        //DEBUG
        //System.err.println("Clearing cache " + this);

        Object [] keys = cachedObjectsHash.keySet().toArray();
        for (int i=0; i<keys.length; i++) {
            remove(keys[i]);
        }

        //Now, reset all containers.
        cachedObjectsHash.clear();
        cachedObjectsHash = new HashMap(103);
        lastAccessedList.clear();
        lastAccessedList = new LinkedList();
        ageList.clear();
        ageList = new LinkedList();

        size = 0;
        cacheHits = 0;
        cacheMisses = 0;
    }

    /**
     * Returns a collection view of the values contained in the cache.
     * The Collection is unmodifiable to prevent cache integrity issues.
     *
     * @return a Collection of the cache entries.
     */
    public Collection values() {
        return Collections.unmodifiableCollection(cachedObjectsHash.values());
    }

    /**
     * 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.
     */
    public long getCacheHits() {
        return cacheHits;
    }

    /**
     * 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.
     */
    public long getCacheMisses() {
        return cacheMisses;
    }

    /**
     * Clears all entries out of cache where the entries are older than the
     * maximum defined age.
     */
    private final void deleteExpiredEntries() {
        //Check if expiration is turned on.
        if (maxLifetime <= 0) {
            return;
        }

        //Remove all old entries. To do this, we remove objects from the end
        //of the linked list until they are no longer too old. We get to avoid
        //any hash lookups or looking at any more objects than is strictly
        //neccessary.
        LinkedListNode node = ageList.getLast();
        //If there are no entries in the age list, return.
        if (node == null) {
            return;
        }

        //Determine the expireTime, which is the moment in time that elements
        //should expire from cache. Then, we can do an easy to check to see
        //if the expire time is greater than the expire time.
        long expireTime = currentTime - maxLifetime;

        while(expireTime > node.timestamp) {
            //DEBUG
            //System.err.println("Object with key " + node.object + " expired.");

            //Remove the object
            remove(node.object);

            //Get the next node.
            node = ageList.getLast();
            //If there are no more entries in the age list, return.
            if (node == null) {
                return;
            }
        }
    }

    /**
     * Removes objects from cache if the cache is too full. "Too full" is
     * defined as within 3% of the maximum cache size. Whenever the cache is
     * is too big, the least frequently used elements are deleted until the
     * cache is at least 10% empty.
     */
    private final void cullCache() {
        //See if the cache size is within 3% of being too big. If so, clean out
        //cache until it's 10% free.
        if (size >= maxSize * .97) {
            //First, delete any old entries to see how much memory that frees.
            deleteExpiredEntries();
            int desiredSize = (int)(maxSize * .90);
            while (size > desiredSize) {
                //Get the key and invoke the remove method on it.
                remove(lastAccessedList.getLast().object);
            }
        }
    }
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产成人啪午夜精品网站男同| 色一区在线观看| 美女网站色91| 日韩电影免费一区| 青青草精品视频| 午夜免费久久看| 五月天亚洲婷婷| 日韩电影在线观看电影| 蜜臀91精品一区二区三区| 日本欧美肥老太交大片| 蜜臀久久99精品久久久久久9| 免费在线视频一区| 九九久久精品视频| 国产福利一区二区三区在线视频| 国产丶欧美丶日本不卡视频| 高清在线不卡av| 成人福利视频网站| 色哟哟在线观看一区二区三区| 成人av资源下载| 色噜噜狠狠色综合中国 | 欧美女孩性生活视频| 欧美性生活久久| 欧美男女性生活在线直播观看| 欧美一区二区三区在| xf在线a精品一区二区视频网站| 中文字幕乱码日本亚洲一区二区| 亚洲三级电影全部在线观看高清| 亚洲一区二区三区自拍| 石原莉奈在线亚洲二区| 精品午夜久久福利影院| 成人在线视频首页| 欧美在线观看18| 日韩手机在线导航| 日本一区二区视频在线观看| 一区二区三区视频在线看| 日韩主播视频在线| 国产精品正在播放| 欧洲生活片亚洲生活在线观看| 日韩视频一区二区| 欧美国产在线观看| 亚洲一区二区3| 国产在线精品一区二区| 99这里只有久久精品视频| 在线亚洲欧美专区二区| 26uuu久久天堂性欧美| 国产精品久久久久久久第一福利| 亚洲第四色夜色| 国产一区二区三区最好精华液 | 欧美韩日一区二区三区| 亚洲女同ⅹxx女同tv| 久久福利资源站| 色综合天天视频在线观看| 欧美成人午夜电影| 亚洲三级免费电影| 国产精品自拍一区| 欧美精品乱码久久久久久按摩 | 亚洲一区二区三区小说| 国产综合色视频| 欧美色精品天天在线观看视频| 久久中文字幕电影| 午夜视频久久久久久| 成人黄色777网| 日韩美女主播在线视频一区二区三区| 亚洲日穴在线视频| 国精产品一区一区三区mba桃花| 欧美视频一区二区三区在线观看| 久久久不卡网国产精品一区| 亚洲丶国产丶欧美一区二区三区| 成人在线视频一区二区| 欧美一区二区三区视频在线| 亚洲精品视频一区二区| 国产精华液一区二区三区| 欧美日韩黄视频| 亚洲欧美日韩国产中文在线| 国产激情精品久久久第一区二区 | 精品国产免费人成在线观看| 一区二区三区精品| 成人高清在线视频| 久久亚洲一区二区三区明星换脸| 亚洲地区一二三色| 色香蕉久久蜜桃| 国产精品全国免费观看高清 | 久久成人免费日本黄色| 欧美三级在线播放| 亚洲精品国产品国语在线app| 成人伦理片在线| 久久久久久久久久久99999| 免费人成在线不卡| 在线成人午夜影院| 亚洲高清一区二区三区| 欧美色图12p| 亚洲黄色av一区| 色综合婷婷久久| 亚洲日本一区二区| 不卡高清视频专区| 国产精品美日韩| 成人a区在线观看| 国产精品久久久久久一区二区三区| 国产精品一区二区三区网站| 久久久久久亚洲综合影院红桃 | 不卡视频在线看| 中文字幕第一区| 成人黄色软件下载| 亚洲欧洲日产国产综合网| 成人免费观看视频| 国产精品久久久久影院| 不卡一卡二卡三乱码免费网站| 欧美国产激情一区二区三区蜜月 | 久久久精品tv| 国产精品中文有码| 国产精品久久久久久久久晋中 | 日韩一区二区三区在线观看| 日韩电影免费在线| 久久天天做天天爱综合色| 国产一区999| 国产精品传媒视频| 色噜噜狠狠成人网p站| 亚洲一区二区三区小说| 欧美猛男超大videosgay| 午夜精品在线看| 精品少妇一区二区三区| 懂色中文一区二区在线播放| **欧美大码日韩| 欧美三区免费完整视频在线观看| 日韩电影在线观看网站| 久久综合狠狠综合久久综合88 | 狠狠网亚洲精品| 国产亚洲成av人在线观看导航| 国产91精品久久久久久久网曝门| 国产精品国产自产拍高清av王其| 一本到不卡精品视频在线观看| 亚洲超碰精品一区二区| 欧美不卡一二三| 成人免费视频一区| 亚洲福利视频一区二区| 2023国产精品视频| 91一区二区三区在线观看| 亚洲大型综合色站| 2欧美一区二区三区在线观看视频| 成人综合婷婷国产精品久久| 亚洲激情图片一区| 精品三级在线观看| 99视频热这里只有精品免费| 亚洲成a人v欧美综合天堂| 精品国产免费人成电影在线观看四季| 成人国产精品免费观看视频| 午夜欧美电影在线观看| 久久久美女艺术照精彩视频福利播放| 91免费观看视频| 久久电影国产免费久久电影| 亚洲男人都懂的| 精品国产乱码久久久久久牛牛| 91在线观看一区二区| 免费观看成人av| 亚洲欧美偷拍卡通变态| 精品处破学生在线二十三| 91国偷自产一区二区开放时间| 麻豆精品蜜桃视频网站| 亚洲视频在线一区观看| 精品少妇一区二区三区在线视频| 色哟哟一区二区在线观看| 国产一区二区三区在线观看精品| 亚洲一区二区黄色| 国产精品久久久久久久久果冻传媒 | 五月天精品一区二区三区| 国产精品色哟哟| 91精品国产美女浴室洗澡无遮挡| 99这里只有久久精品视频| 精品一区二区三区免费视频| 亚洲国产精品精华液网站| 久久精品欧美日韩| 欧美一区二区三区免费大片| 色婷婷综合视频在线观看| 国内不卡的二区三区中文字幕 | 99久久精品国产精品久久| 美国十次了思思久久精品导航| 亚洲激情在线播放| 国产精品色在线观看| 精品91自产拍在线观看一区| 欧美三级一区二区| 91美女在线看| 粉嫩绯色av一区二区在线观看 | 久久伊99综合婷婷久久伊| 91精品久久久久久久99蜜桃| 色欲综合视频天天天| 大尺度一区二区| 国产精品一级在线| 久久精品国产成人一区二区三区| 亚洲成人自拍一区| 亚洲黄一区二区三区| 国产精品久久二区二区| 国产区在线观看成人精品| 欧美xingq一区二区| 4hu四虎永久在线影院成人| 色呦呦国产精品| 91在线看国产| 91在线视频免费91| 91欧美一区二区| 91视频91自| 色悠悠久久综合|