private V doGet()

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


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

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

            if (debug && 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);
            }
            final 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<>(key, val, refq));
        } else if (debug) {
            this.countGetHitMemory.incrementAndGet();
        }
        // cache value exists.
        return val;
    }