All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.camel.util.LRUWeakCache Maven / Gradle / Ivy

There is a newer version: 4.6.0
Show newest version
/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.camel.util;

/**
 * A cache that uses a near optional LRU Cache using {@link java.lang.ref.WeakReference}.
 * 

* The Cache is implemented by Caffeine which provides an efficient cache. *

* This implementation uses {@link java.lang.ref.WeakReference} for stored values in the cache, to support the JVM * when it wants to reclaim objects for example during garbage collection. Therefore this implementation does * not support all the {@link java.util.Map} methods. *

* The following methods is only be be used: *

    *
  • containsKey - To determine if the key is in the cache and refers to a value
  • *
  • entrySet - To return a set of all the entries (as key/value paris)
  • *
  • get - To get a value from the cache
  • *
  • isEmpty - To determine if the cache contains any values
  • *
  • keySet - To return a set of the current keys which refers to a value
  • *
  • put - To add a value to the cache
  • *
  • putAll - To add values to the cache
  • *
  • remove - To remove a value from the cache by its key
  • *
  • size - To get the current size
  • *
  • values - To return a copy of all the value in a list
  • *
*

* The {@link #containsValue(Object)} method should not be used as it's not adjusted to check * for the existence of a value without catering for the soft references. *

* Notice that if the JVM reclaim memory the content of this cache may be garbage collected, without any * eviction notifications. * * @see LRUCache * @see LRUSoftCache */ public class LRUWeakCache extends LRUCache { public LRUWeakCache(int maximumCacheSize) { this(16, maximumCacheSize); } public LRUWeakCache(int initialCapacity, int maximumCacheSize) { super(initialCapacity, maximumCacheSize, false, false, true, false); } @Override public String toString() { return "LRUWeakCache@" + ObjectHelper.getIdentityHashCode(this); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy