SoftCacheStorage (FreeMarker 2.3.35 API)
Description: declaration: package: freemarker.cache, class: SoftCacheStorage

Package freemarker.cache

# Class SoftCacheStorage

java.lang.Object
freemarker.cache.SoftCacheStorage

All Implemented Interfaces:
  `CacheStorage`, `CacheStorageWithGetSize`, `ConcurrentCacheStorage`

public class SoftCacheStorage extends Object implements ConcurrentCacheStorage, CacheStorageWithGetSize
Soft cache storage is a cache storage that uses `SoftReference` objects to hold the objects it was passed, therefore allows the garbage collector to purge the cache when it determines that it wants to free up memory. This class is thread-safe to the extent that its underlying map is. The parameterless constructor uses a thread-safe map since 2.3.24 or Java 5.

See Also:
  `Configuration.setCacheStorage(CacheStorage)`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SoftCacheStorage()`
  Creates an instance that uses a `ConcurrentMap` internally.
  `SoftCacheStorage​(Map backingMap)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clear()`
  `Object`
  `get​(Object key)`
  `int`
  `getSize()`
  Returns a close approximation of the number of cache entries.
  `boolean`
  `isConcurrent()`
  Returns true if the underlying Map is a `ConcurrentMap`.
  `void`
  `put​(Object key, Object value)`
  `void`
  `remove​(Object key)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### SoftCacheStorage

    public SoftCacheStorage()
    Creates an instance that uses a `ConcurrentMap` internally.

  - ### SoftCacheStorage

    public SoftCacheStorage​(Map backingMap)

- ## Method Details

  - ### isConcurrent

    public boolean isConcurrent()
    Returns true if the underlying Map is a `ConcurrentMap`.
    Specified by:
      `isConcurrent` in interface `ConcurrentCacheStorage`
    Returns:
      true if this instance of cache storage is concurrently accessible from multiple threads without synchronization.

  - ### get

    public Object get​(Object key)
    Specified by:
      `get` in interface `CacheStorage`

  - ### put

    public void put​(Object key, Object value)
    Specified by:
      `put` in interface `CacheStorage`

  - ### remove

    public void remove​(Object key)
    Specified by:
      `remove` in interface `CacheStorage`

  - ### clear

    public void clear()
    Specified by:
      `clear` in interface `CacheStorage`

  - ### getSize

    public int getSize()
    Returns a close approximation of the number of cache entries.
    Specified by:
      `getSize` in interface `CacheStorageWithGetSize`
    Since:
      2.3.21