private V doPut()

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


    private V doPut(@NonNullable String key, @NonNullable V value) {
        KeyedSoftReference<String,V> oldRef =
                map.put(key, new KeyedSoftReference<String,V>(key, value, refq));
        V ret = null;

        if (oldRef != null) {
            ret = oldRef.get();
            oldRef.clear();

            if (debug)
                this.countPutClearRef.incrementAndGet();
        }
        if (ret == null) {
            // Not in memory.
            if (debug)
                this.countPutMissMemory.incrementAndGet();
            if (value instanceof Serializable) {
                // Try the file system.
                if (debug)
                    this.countPutSerializable.incrementAndGet();
                CacheFileContent cfc = CacheFileDAO.inst.readCacheItem(this.name, key);

                if (cfc != null) {
                    if (debug)
                        this.countPutReadFile.incrementAndGet();
                    ret = (V)cfc.deserialize();
                }
                if (!EqualsUtils.inst.equals(value, ret)) {
                    // Considered new value being put to memory.
                    // So persist to file system.
                    if (debug) {
                        this.countPutNewFileValue.incrementAndGet();
                        this.countPutWriteFile.incrementAndGet();
                    }
                    byte[] ba = SerializationUtils.serialize((Serializable)value);
                    CacheFileDAO.inst.writeCacheItem(
                        this.name, CacheFileContentType.JAVA_SERIALIZATION, key, ba);
                }
            }
            return ret;
        }
        // ret must be non-null.
        // Found in memory
        if (!EqualsUtils.inst.equals(value, ret)) {
            if (debug)
                this.countPutNewMemoryValue.incrementAndGet();
            // Different value being put to memory.
            if (value instanceof Serializable) {
                // Persist to file system.
                if (debug) {
                    this.countPutSerializable.incrementAndGet();
                    this.countPutWriteFile.incrementAndGet();
                }
                byte[] ba = SerializationUtils.serialize((Serializable)value);
                CacheFileDAO.inst.writeCacheItem(
                    this.name, CacheFileContentType.JAVA_SERIALIZATION, key, ba);
            }
        }
        return ret;
    }