Package org.eclipse.xtext.util
Class OnChangeEvictingCache
- java.lang.Object
-
- org.eclipse.xtext.util.OnChangeEvictingCache
-
- All Implemented Interfaces:
IResourceScopeCache
public class OnChangeEvictingCache extends java.lang.Object implements IResourceScopeCache
A cache implementation that stores its values in the scope of a resource. The values will be discarded as soon as the contents of the resource changes semantically. Clients may override this behavior for certain transactions by means ofexecWithoutCacheClear(Resource, IUnitOfWork)orexecWithTemporaryCaching(Resource, IUnitOfWork).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOnChangeEvictingCache.CacheAdapterstatic interfaceOnChangeEvictingCache.ListenerA simple cache listener.-
Nested classes/interfaces inherited from interface org.eclipse.xtext.util.IResourceScopeCache
IResourceScopeCache.NullImpl
-
-
Constructor Summary
Constructors Constructor Description OnChangeEvictingCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcacheHit(OnChangeEvictingCache.CacheAdapter adapter)Announce a cache hit for the internal statistics of the adapter.protected voidcacheMiss(OnChangeEvictingCache.CacheAdapter adapter)Announce a cache miss for the internal statistics of the adapter.voidclear(org.eclipse.emf.ecore.resource.Resource resource)Clears the cache of the given resource.protected OnChangeEvictingCache.CacheAdaptercreateCacheAdapter()<Result,Param extends org.eclipse.emf.ecore.resource.Resource>
ResultexecWithoutCacheClear(Param resource, IUnitOfWork<Result,Param> transaction)The transaction will be executed.<Result,Param extends org.eclipse.emf.ecore.resource.Resource>
ResultexecWithTemporaryCaching(Param resource, IUnitOfWork<Result,Param> transaction)The transaction will be executed with caching enabled.protected OnChangeEvictingCache.CacheAdapterfindCacheAdapter(org.eclipse.emf.ecore.resource.Resource resource)<T> Tget(java.lang.Object key, org.eclipse.emf.ecore.resource.Resource resource, com.google.inject.Provider<T> provider)Try to obtain the value that is cached for the given key in the given resource.OnChangeEvictingCache.CacheAdaptergetOrCreate(org.eclipse.emf.ecore.resource.Resource resource)Returns the cache adapter that is associated with the resource.
-
-
-
Method Detail
-
clear
public void clear(org.eclipse.emf.ecore.resource.Resource resource)
Clears the cache of the given resource.- Specified by:
clearin interfaceIResourceScopeCache
-
get
public <T> T get(java.lang.Object key, org.eclipse.emf.ecore.resource.Resource resource, com.google.inject.Provider<T> provider)Try to obtain the value that is cached for the given key in the given resource. If no value is cached, the provider is used to compute it and store it afterwards.- Specified by:
getin interfaceIResourceScopeCache- Parameters:
resource- the resource. If it isnull, the provider will be used to compute the value.key- the cache key. May not benull.provider- the strategy to compute the value if necessary. May not benull.- Returns:
- the cached value or what the provider returns if no cached value exists
-
cacheMiss
protected void cacheMiss(OnChangeEvictingCache.CacheAdapter adapter)
Announce a cache miss for the internal statistics of the adapter.- Since:
- 2.1
-
cacheHit
protected void cacheHit(OnChangeEvictingCache.CacheAdapter adapter)
Announce a cache hit for the internal statistics of the adapter.- Since:
- 2.1
-
getOrCreate
public OnChangeEvictingCache.CacheAdapter getOrCreate(org.eclipse.emf.ecore.resource.Resource resource)
Returns the cache adapter that is associated with the resource. The life cycle of the cache is strongly connected to the resource and its change notifications. Will not returnnull.- Parameters:
resource- the resource. May not benull.- Returns:
- the cache adapter for the given resource. Never
null.
-
findCacheAdapter
protected OnChangeEvictingCache.CacheAdapter findCacheAdapter(org.eclipse.emf.ecore.resource.Resource resource)
- Since:
- 2.26
-
createCacheAdapter
protected OnChangeEvictingCache.CacheAdapter createCacheAdapter()
- Since:
- 2.23
-
execWithoutCacheClear
public <Result,Param extends org.eclipse.emf.ecore.resource.Resource> Result execWithoutCacheClear(Param resource, IUnitOfWork<Result,Param> transaction) throws org.eclipse.emf.common.util.WrappedExceptionThe transaction will be executed. While it is running, any semantic state change in the given resource will be ignored and the cache will not be cleared.- Throws:
org.eclipse.emf.common.util.WrappedException
-
execWithTemporaryCaching
public <Result,Param extends org.eclipse.emf.ecore.resource.Resource> Result execWithTemporaryCaching(Param resource, IUnitOfWork<Result,Param> transaction) throws org.eclipse.emf.common.util.WrappedExceptionThe transaction will be executed with caching enabled. However, all newly cached values will be discarded as soon as the transaction is over.- Throws:
org.eclipse.emf.common.util.WrappedException- Since:
- 2.1
-
-