private V doGet()

in commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/soft/SoftRefFileCache.java [192:246]


    private V doGet(String key) {
        KeyedSoftReference<String,V> ref = map.get(key);
        V val = null;

        if (ref != null) {
            val = ref.get();

            if (debug) {
                if (val == null)
                    this.countGetEmptyRef.incrementAndGet();
            }
        }
        else {
            if (debug)
                this.countGetMissMemory.incrementAndGet();
        }
        if (val == null) {
            // Not in memory.
            if (ref != null) {
                // Rarely gets here, if ever.
                // GC'd.  So try to clean up the key/ref pair.
                this.map.remove(key,  ref);
            }
            CacheFileContent cfc = CacheFileDAO.inst.readCacheItem(this.name, key);

            if (cfc == null) {
                // Not in file system.
                if (debug)
                    this.countGetMiss.incrementAndGet();
                return null;
            }
            // Found in file system.
            if (debug)
                this.countGetHitFile.incrementAndGet();
            val = (V)cfc.deserialize();

            if (val == null) {
                // Corrupted file.  Try remove it from file system.
                if (debug)
                    this.countGetCorruptedFile.incrementAndGet();
                // Don't think I need to put a read lock on the cache for removal.
                CacheFileDAO.inst.removeCacheItem(this.name, key);
                return null;
            }
            // Resurrect item back to memory.
            map.putIfAbsent(key,
                    new KeyedSoftReference<String,V>(key, val, refq));
        }
        else {
            if (debug)
                this.countGetHitMemory.incrementAndGet();
        }
        // cache value exists.
        return val;
    }