Eviction policies using the disk cache garbage collector

The disk cache garbage collector is responsible for evicting objects out of the disk cache, based on a specified eviction policy.

The garbage collector keeps a certain amount of space on disk available, which is governed by the configuration attribute that limits the amount of disk space that is used for caching objects. To enable the eviction policy, enable the Limit disk cache size in GB and/or Limit disk cache size in entries options in the administrative console.

The garbage collector is triggered when the disk space reaches a specified high threshold (a percentage of the Limit disk cache size in entries or in GB) and evicts objects, based on the eviction policy, from the disk in the background until the disk cache size reaches a specified low threshold (a percentage of the Limit disk cache size in entries or in GB). Eviction triggers when one or both of the high thresholds is reached for Limit disk cache size in GB and Limit disk cache size in entries. The supported policies are:
  • None: This is the default policy. Objects are evicted only when they expire, or if they are invalidated.
  • Random: The expired objects are removed first. If the disk size still has not reached the low threshold limit, objects are picked from the disk cache in random order and removed until the disk size reaches a low threshold limit.
  • Size: The expired objects are removed first. If the disk size still has not reached the low threshold limit, then largest-sized objects are removed until the disk size reaches a low threshold limit.

Limit disk cache size in GB and High Threshold determines when to trigger eviction and when the disk cache is considered near full. It is computed as a function of the user-specified limit. If the specified limit is 10 GB (3 GB is the minimum), the cache subsystem initially creates three files that can grow to 1 GB in size for cache data, dependency ID information, and template information. Each time more space is needed to contain cache data, dependency ID information, or template information, a new file is created. Each of these files grow in 1 GB increments until the total number of files that are created is equal to disk cache in size in GB (in this case ten). Although the initial size of the new file may be much smaller than 1 GB, the dynamic cache service always rounds up to the next GB.

Eviction triggers when the cache data size reaches the high threshold and continues until the cache data size reaches the low threshold. Calculation of cache data size is dynamic. The following formula describes how to calculate the actual cache data size limit:

cache data size limit = disk cache size (in GB) - number of dependency files per GB - number of template files  
When the cache data size limit is defined, the trigger point is calculated as follows:
eviction trigger point = cache data size limit * high threshold
size of evicted entries = cache data size * (high threshold - low threshold)
Consider the following scenarios:
  • Scenario 1
    • Disk cache size in GB = 10 GB
    • High threshold = 90%
    • Low Threshold = 80%
    Initially, there is one file for dependency ID and template ID.
    cache data size limit = 10-(1+1) = 8 GB
    eviction trigger point = 8 * 90% = 7.2 GB
    size of evicted entries = 8 * (90% - 80%) = 0.8 GB
    In the previous scenario, eviction starts when the data cache size reaches 7.2 GB and continues until the cache size is 6.4 GB (7.2 - 0.8).
  • Scenario 2
    In scenario 1, if the dependency files grow to more than 1 GB, an additional dependency file generates. The eviction trigger point launches dynamically as follows:
    cache data size limit = 10 - (2+1) = 7GB
    eviction trigger point = 7 * 90% = 6.3GB
    size of evicted entries = 7 * (90% - 80%) = 0.7GB
    
    In the previous scenario, eviction starts when the data cache size reaches 6.3 GB, and continues until the cache size in 5.6 GB (6.3 - 0.7).
Disk cache eviction for limit disk cache size in entries. Consider the following scenario:
  • Disk cache size in entries = 100000
  • High threshold = 90%
  • Low threshold = 80%
eviction trigger point = 100000 * 90% = 90000
number of entries evicted = 100000 * (90% - 80%) = 10000
In this scenario, eviction starts when the number of cache entries reaches 90000 and 10000 entries are evicted from the cache.