Interface ScopeCache
- All Known Implementing Classes:
StandardScopeCache,ThreadLocalScopeCache
public interface ScopeCache
A special-purpose cache interface specifically for the
GenericScope to use to
manage cached bean instances. Implementations generally fall into two categories: those
that store values "globally" (i.e. one instance per key), and those that store
potentially multiple instances per key based on context (e.g. via a thread local). All
implementations should be thread safe.- Author:
- Dave Syer
-
Method Summary
Modifier and TypeMethodDescriptionclear()Clears the cache and returns all objects in an unmodifiable collection.Gets the named object from the cache.Put a value in the cache if the key is not already used.Removes the object with this name from the cache.default booleanReturns whether instances stored in this cache can be accessed concurrently by multiple threads, in which caseGenericScopeguards proxied invocations with read/write locks to protect them from concurrent destruction.
-
Method Details
-
remove
Removes the object with this name from the cache.- Parameters:
name- The object name.- Returns:
- The object removed, or null if there was none.
-
clear
Collection<Object> clear()Clears the cache and returns all objects in an unmodifiable collection.- Returns:
- All objects stored in the cache.
-
get
Gets the named object from the cache.- Parameters:
name- The name of the object.- Returns:
- The object with that name, or null if there is none.
-
put
Put a value in the cache if the key is not already used. If one is already present with the name provided, it is not replaced, but is returned to the caller.- Parameters:
name- The key.value- The new candidate value.- Returns:
- The value that is in the cache at the end of the operation.
-
requiresLocking
default boolean requiresLocking()Returns whether instances stored in this cache can be accessed concurrently by multiple threads, in which caseGenericScopeguards proxied invocations with read/write locks to protect them from concurrent destruction. Caches whose instances are confined to a single thread (e.g. backed by a thread local) should returnfalseso that locking can be skipped (see gh-630).- Returns:
- whether proxied invocations require locking; default
true
-