Interface CacheManager

  • All Known Implementing Classes:
    CacheManagerImpl

    public interface CacheManager

    Use this interface to retrieve all existing Cache names and interact with any cache programmatically e.g. store, retrieve or delete cache values. It shares the same caches collection the Quarkus caching annotations use. The CacheName annotation can also be used to inject and access a specific cache from its name.

    Code example:

     @ApplicationScoped
     public class CachedService {
    
         @Inject
         CacheManager cacheManager;
    
         String getExpensiveValue(Object key) {
             Cache cache = cacheManager.getCache("my-cache");
             Uni<String> cacheValue = cache.get(key, () -> expensiveService.getValue(key));
             return cacheValue.await().indefinitely();
         }
     }
     

    • Method Detail

      • getCacheNames

        Collection<String> getCacheNames()
        Gets a collection of all cache names.
        Returns:
        names of all caches
      • getCache

        Optional<Cache> getCache​(String name)
        Gets the cache identified by the given name.
        Parameters:
        name - cache name
        Returns:
        an Optional containing the identified cache if it exists, or an empty Optional otherwise