Interface CacheService

All Known Implementing Classes:
AndroidCacheService, DefaultCacheService, DesktopCacheService, DummyCacheService, IOSCacheService

public interface CacheService
The cache service provides a simple API to weakly cache objects in memory. There is no guarantee that items being put in the cache will be retained for any minimum amount of time. They will be garbage collected when necessary.

Example

 CacheService.create().ifPresent(service -> {
      Cache<String, String> cache = service.getCache("simpleCache");
      cache.put("key", "value");
      String value = cache.get("key");
  });

Android Configuration: none

iOS Configuration: none

Since:
3.0.0
  • Method Details

    • create

      static Optional<CacheService> create()
      Returns an instance of CacheService.
      Returns:
      An instance of CacheService.
    • getCache

      <K, V> Cache<K,V> getCache(String cacheName)
      Returns a Cache instance. The name is used to allow for multiple cache instances to be created, with the name being a unique identifier, returning the same cache every time when given the same name.
      Type Parameters:
      K - The key type for the cache
      V - The value type for the cache
      Parameters:
      cacheName - The name of the cache.
      Returns:
      A named Cache instance.