KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Customizing the amount of cache to unload when the cache reaches 100%
PRODUCT: 4D | VERSION: 16 R4 | PLATFORM: Mac & Win
Published On: March 8, 2018

When the amount of used cache reaches 100% the 4D Server application will automatically unload some of the cache to free up room. By default, 4D unloads at least 10% of the cache when space is needed.

Because a percentage is used by default, the actual amount of memory unloaded will depend on the actual maximum cache value.

For example, if you have 20 GB set for the maximum cache, 4D will unload 2 GB.
Conversely, if you have 200 GB set for the maximum cache, 4D will unload 20 GB.

As demonstrated above, setting a very large cache size will directly cause this 10% to also be very large.

To optimize performance, the developer can customize the amount of cache to unload. This is accomplished via the SET DATABASE PARAMETER command using selector 66 Cache unload minimum size.

When customizing this, the value is expressed in bytes.

The following code snippets set the cache unload to 1 GB if the current size is greater than 10 GB:

In v16 R4 and newer you can use the GET CACHE SIZE command:

C_REAL($cacheBytes)
$cacheBytes:=Get cache size // v16 R4 and after
If ($cacheBytes>(10*1024*1024*1024))
    // if current cache is greater than 10 GB
    SET DATABASE PARAMETER(Cache unload minimum size;1*1024*1024*1024)
    // set unload size to 1 GB
End if


In versions prior to v16 R4 you would need to use selector #9 (Database cache size) for GET DATABASE PARAMATER to obtain the current cache size:
C_REAL($cacheBytes)
$cacheBytes:=Get database parameter(_o_Database cache size)// prior to v16 R4
If ($cacheBytes>(10*1024*1024*1024))
    // if current cache is greater than 10 GB
    SET DATABASE PARAMETER(Cache unload minimum size;1*1024*1024*1024)
    // set unload size to 1 GB
End if