Class ThreadLocalScopeCache
java.lang.Object
org.springframework.cloud.context.scope.thread.ThreadLocalScopeCache
- All Implemented Interfaces:
ScopeCache
- Author:
- Dave Syer
-
Constructor Summary
Constructors -
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.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.
-
Constructor Details
-
ThreadLocalScopeCache
public ThreadLocalScopeCache()
-
-
Method Details
-
remove
Description copied from interface:ScopeCacheRemoves the object with this name from the cache.- Specified by:
removein interfaceScopeCache- Parameters:
name- The object name.- Returns:
- The object removed, or null if there was none.
-
clear
Description copied from interface:ScopeCacheClears the cache and returns all objects in an unmodifiable collection.- Specified by:
clearin interfaceScopeCache- Returns:
- All objects stored in the cache.
-
get
Description copied from interface:ScopeCacheGets the named object from the cache.- Specified by:
getin interfaceScopeCache- Parameters:
name- The name of the object.- Returns:
- The object with that name, or null if there is none.
-
put
Description copied from interface:ScopeCachePut 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.- Specified by:
putin interfaceScopeCache- Parameters:
name- The key.value- The new candidate value.- Returns:
- The value that is in the cache at the end of the operation.
-
requiresLocking
public boolean requiresLocking()Description copied from interface:ScopeCacheReturns 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).- Specified by:
requiresLockingin interfaceScopeCache- Returns:
- whether proxied invocations require locking; default
true
-