Replaces the specified key only if it has some current value.
@param key the key to replace
@param val the new value
@return whatever is stored in the cache for the key when the operation completes
187431
public V replace(K key, V val) {
       // synchronized( this ) {
            if( !containsKey(key) ) {
                return null;
            }
            return put(key, val);
        //}
    }
901120
public synchronized ValT put(KeyT key, ValT value) {
        if (isDiskCacheEnabled) {
            cacheToDisk(key, value);
        }

        return cache.put(key, value);
    }
716624
public boolean replace( Long key, TypeV oldValue, TypeV newValue ) {
    return replace(key.longValue(), oldValue, newValue);
  }
33239
public VALUE get(KEY key) {
        CacheEntry<VALUE> entry;
        synchronized (this) {
            entry = values.get(key);
        }
        VALUE value;
        if (entry != null) {
            if (isExpiring) {
                long age = System.currentTimeMillis() - entry.timeCreated;
                if (age < expirationMillis) {
                    value = getValue(key, entry);
                } else {
                    countExpired++;
                    synchronized (this) {
                        values.remove(key);
                    }
                    value = null;
                }
            } else {
                value = getValue(key, entry);
            }
        } else {
            value = null;
        }
        if (value != null) {
            countHit++;
        } else {
            countMiss++;
        }
        return value;
    }
777995
@Nullable
  public synchronized V put(K key, V value) {
    // We do remove and insert instead of just replace, in order to cause a structural change
    // to the map, as we always want the latest inserted element to be last in the queue.
    V oldValue = mMap.remove(key);
    mSizeInBytes -= getValueSizeInBytes(oldValue);
    mMap.put(key, value);
    mSizeInBytes += getValueSizeInBytes(value);
    return oldValue;
  }
777102
public function cache($key, callable $val)
    {
        if (!array_key_exists($key, $this->cache)) {
            $this->cache[$key] = $val();
        }

        return $this->cache[$key];
    }
1088970
function (key, val) {
    if (this._cache[key]) {
      return this._cache[key];
    }
    if (typeof val === 'function') {
      val = val.call(this);
    }
    return (this._cache[key] = val);
  }
905885
public final V put(String key, V newValue) {
        V oldValue = mMemCache.put(key, newValue);
        putToDiskQuietly(key, newValue);
        return oldValue;
    }
1065392
public synchronized Object put(final String key, final Object value) {
		try {
			if (maxCacheSize == 0) {
				return null;
			}

			// if the key isn't in the cache and the cache is full...
			if (!super.containsKey(key) && !list.isEmpty()
					&& list.size() + 1 > maxCacheSize) {
				final Object deadKey = list.removeLast();
				super.remove(deadKey);
			}

			updateKey(key);
		} catch (Exception e) {
			log.log(Level.SEVERE, "put", e);
		}
		return super.put(key, value);
	}
1273999
public void replaceValues(String key, Object value) {
//    fields.replaceValues(key, Collections.singletonList(value)); // unnecessarily slow
    List<Object> list = fields.get(key);
    list.clear(); 
    list.add(value);
  }
700600
public function set($key, $val = null)
    {
        if (is_array($key)) {
            $this->locals = array_merge($this->locals->all(), $key);
        } else {
            $this->locals[$key] = $val;
        }
        return $this;
    }
371424
public V put(K key, V value) {
	V old = super.put(key, value);
	if (size() > bound) {
	    remove(firstKey());
	}
	return old;
    }
1236537
public V remove (K key) {
		int hashCode = key.hashCode();
		int index = hashCode & mask;
		if (key.equals(keyTable[index])) {
			keyTable[index] = null;
			V oldValue = valueTable[index];
			valueTable[index] = null;
			size--;
			return oldValue;
		}

		index = hash2(hashCode);
		if (key.equals(keyTable[index])) {
			keyTable[index] = null;
			V oldValue = valueTable[index];
			valueTable[index] = null;
			size--;
			return oldValue;
		}

		index = hash3(hashCode);
		if (key.equals(keyTable[index])) {
			keyTable[index] = null;
			V oldValue = valueTable[index];
			valueTable[index] = null;
			size--;
			return oldValue;
		}

		if (bigTable) {
			index = hash4(hashCode);
			if (key.equals(keyTable[index])) {
				keyTable[index] = null;
				V oldValue = valueTable[index];
				valueTable[index] = null;
				size--;
				return oldValue;
			}
		}

		return removeStash(key);
	}
976973
public static <T> Maybe<List<T>> values(String key, Class<T> vClazz) {
        return values(CacheService.CACHE_CONFIG_BEAN, key, vClazz);
    }
85885
public V put(long key, V val) {
		if (size == 0) {
			rootKey = key;
			rootVal = val;
			size++;
			return null;
		}
		if (size == 1) {
			Node<V> n2 = createNode(key, val, rootKey, rootVal, 0);
			if (n2 == null) {
				V prev = rootVal;
				rootVal = val;
				return prev; 
			}
			root = n2;
			rootKey = 0;
			rootVal = null;
			size++;
			return null;
		}
		Node<V> n = root;
		while (true) {
			if (n.posFirstBit != n.posDiff) {
				//split infix?
				int posDiff = compare(key, n.infix);
				if (posDiff < n.posDiff && posDiff != -1) {
					long subInfix = extractInfix(n.infix, n.posDiff-1);
					//new sub-node
					Node<V> newSub = new Node<V>(posDiff+1, n.loPost, n.loVal, n.hiPost, n.hiVal, 
							subInfix, n.posDiff);
					newSub.hi = n.hi;
					newSub.lo = n.lo;
					if (getBit(key, posDiff)) {
						n.hi = null;
						n.hiPost = key;
						n.hiVal = val;
						n.lo = newSub;
						n.loPost = 0;
						n.loVal = null;
					} else {
						n.hi = newSub;
						n.hiPost = 0;
						n.hiVal = null;
						n.lo = null;
						n.loPost = key;
						n.loVal = val;
					}
					n.infix = extractInfix(key, posDiff-1);
					n.posDiff = posDiff;
					size++;
					return null;
				}
			}			
			
			//infix matches, so now we check sub-nodes and postfixes
			if (getBit(key, n.posDiff)) {
				if (n.hi != null) {
					n = n.hi;
					continue;
				} else {
					Node<V> n2 = createNode(key, val, n.hiPost, n.hiVal, n.posDiff + 1);
					if (n2 == null) {
						V prev = n.hiVal;
						n.hiVal = val;
						return prev; 
					}
					n.hi = n2;
					n.hiPost = 0;
					n.hiVal = null;
					size++;
					return null;
				}
			} else {
				if (n.lo != null) {
					n = n.lo;
					continue;
				} else {
					Node<V> n2 = createNode(key, val, n.loPost, n.loVal, n.posDiff + 1);
					if (n2 == null) {
						V prev = n.loVal;
						n.loVal = val;
						return prev; 
					}
					n.lo = n2;
					n.loPost = 0;
					n.loVal = null;
					size++;
					return null;
				}
			}
		}
	}
1311664
@Override
    public KVStore putValue(String key, Object val) {
        put(key, ValueObject.of(val));
        return this;
    }
989990
@Override
    public V get(Object key) {
        if (key == null) {
            throw new NullPointerException();
        }
        
        CachedValue<K, V> entry = map.get(key);
        if (entry == null) {
            return null;
        }
        if (isValueExpired(entry)) {
            if (map.remove(key, entry)) {
                onValueRemove(entry);
                return null;
            }
            return get(key);
        }
        return readValue(entry);
    }