Blob Cache in the CAE: Infos and Troubleshooting
Learn some details about the Blob Cache and how to access the cache information.
What you'll learn
- Knowing details about the Blob Cache
Prerequisites
- Blueprint Workspace
- CAE knowledge
Time matters
Should I read this?
The blob cache for the CAE is used to store blobs downloaded from the Content Server. The cache consists of temporary files on disk. The configuration of this cache (for example, location and size) and the default values can be found in the documentation:
Technical Details of the Blob Cache Machinery
Every time com.coremedia.cap.common.Blob.getInputStream()
is called, the CoreMedia Cache is asked to load the InputStream
. This happens in a CacheKey
which uses a TempFileFactory
to write the blob into a temporary file and store it for as long as the blob should be cached. The CacheKey
holds a reference to the temporary file. The weight of the CacheKey
is the size of the blob.
A blob will be removed from the cache if either the cache is full and more space is needed for other blobs or if the CacheKey
is invalidated. When this happens, the CacheKey
frees the reference to the temporary file and the Garbage Collector will remove the reference during its next run. Whenever the TempFileFactory
wants to create a new temporary file, it first deletes all temporary files whose references were destroyed by the Garbage Collector.
If the CAE is stopped, then all temporary files in the blob cache are deleted.
Troubleshooting
If the blob swap doesn’t work as expected and the blob cache fills up with temporary files which are never deleted, this can have several reasons:
-
The Garbage Collector does not run.
-
The deletion of temporary files can fail. In this case, there will be log entries at log-level DEBUG for the class
hox.util.TempFileFactory
which look like "failed to delete unreachable file: xyz". -
There are other places in the (customized) code which hold references to these temporary files. This can happen, for instance, if
FileHandles
orStreams
are not closed properly. In this case, the cache will free the reference to the temporary file. However, since the Garbage Collector does not destroy all references to the file, theTempFileFactory
will never be informed that the blob has been removed from the cache. Thus, theTempFileFactory
will not delete the file. This file will be removed when the CAE is stopped.
Note that a hard maximum on the folder size on disk cannot be set. The actual folder size is always going to be a factor bigger than the configured blob cache size. If you think that the folder size on disk is too big, check to see if the size is steadily increasing or if the size stabilizes around a particular value. In the latter case, there should be no problems if the disk is big enough.
You can use JMX to check if the cache size is correctly calculated. The levels should only exceed the capacity minimally. The values are given in bytes.
-
Cache limit: MBeans → com.coremedia.cap.disk → ContentApplicationEngine → Attributes → Capacities
-
Current cache size: MBeans → com.coremedia.cap.disk → ContentApplicationEngine → Attributes → Levels
In older versions, there have been problems in the past that the temporary files were not cleaned up when the CAE is stopped suddenly (for example, a kill -9 on the Tomcat process). After the CAE is restarted, the cache will be refilled and these old files will never be used again. If you suspect that this has happened, you may delete all temporary files which have been created before the last restart of the CAE. Do NOT delete any temporary files which belong to the current run of the CAE. This will cause chaos and corruption.