What categories are the build cache of static site generators divided into, and can the cache expiration be set to never expire?
What types of build caches are divided in static site generators, can the cache expiration be set to never expire? The conclusion is that taking Hugo as an example of this type of static generator, it divides the intermediate products into multiple types of caches according to their purposes during the build period, each of which can be set to a separate directory and retention time; if the retention time is set to a negative value, which is -1 in the convention, these entries will never expire. However, never expiring does not mean not cleaning up, as there is another garbage collection switch responsible for deleting unused old files during the build. Whether to extend the retention or clean up regularly depends on the rhythm of the site.
What types of caches are divided during the build period
Static generators render sites by first calculating a batch of reusable intermediate results, such as processed resources, compressed images, and downloaded theme modules. The configuration page of the Hugo official documentation categorizes these results into seven types of file caches: resources, resource queries, image processing, miscellaneous derived data, module git version information, module queries, and module content itself.
They are separated because each category has different volume and update frequency: image processing takes up the most space and is the most time-consuming, while the module content rarely changes after download. After categorization, operations can individually adjust directories or retention time for a particular category without having to clear a large area in a generic manner.
| Cache Type | What is roughly cached | Settable items (dir/maxAge) |
|---|---|---|
| Resources assets | Reusable resources after processing | Set individually |
| Images images | Scaling and cropping and other image results | Set individually |
| Resource query getresource | Resource search result by name | Set individually |
| Modules modules | Download theme or module | Set individually |
| Git information modulegitinfo | Module version library information | Set individually |
| Module query modulequeries | Search results for available modules | Set individually |
| Miscellaneous misc | Other derived data | Set individually |
Can the directory and retention time be adjusted separately
Each type of cache can use dir to specify the directory it falls into, and use maxAge to specify how long to retain, both independently. By default, they are concentrated in a unified cache directory. If a particular type is especially large or needs to be placed on a faster disk, it can be assigned a separate directory for easier mounting and backup.
The retention time determines how long a cache item stays on the disk. Most categories have a shorter default duration unless explicitly set, the documentation mentions that some caches expire on a scale of 24 hours; setting the value to a negative number, as agreed upon by -1, means that these entries never expire and will not disappear automatically over time. This only describes the retention time and is different from the cleaning switch below.
The cost of never expiring and the cleaning switch
After setting the retention time to a negative value, the occupation only increases and does not decrease until new content is continuously written. For sites with frequent construction and a large number of images, it is easy to expand the cache directory and slow down the backup for a long time, so it should be set according to capacity and rhythm, and cannot be set to the bottom without considering the situation.
The real cleaning of leftovers is the garbage collection switch during the construction period, which deletes the old cache files that are no longer in use during the construction. The objects it acts on are the leftovers that are no longer referenced. It complements the expiration by time, one manages how long to keep, and the other manages to clear the unused ones. Only by working together can it speed up and not fill up the disk.
When the construction slows down, first confirm where the cache falls.
When building becomes significantly slower, the first thing to do is not to rush to delete the cache, but to confirm where the slowness is in terms of category and which directory the cache falls into. It is best to first check the configuration of various dir settings and the actual size of the corresponding directory on the disk: if the main part is image processing and there is enough space, extend its retention time even to make it never expire, so that reconstruction can hit as much as possible; if the directory is already very large and the disk is also tight, then clean up regularly by version or rely on the garbage collection switch to delete old residues.
It should be clarified as a prerequisite: the above is for static sites generated during the build period. Systems like AnQiCMS based on Go language do not go through the build period to generate, but organize pages only when requests come, so there is no layer of build cache, retention time, and cleaning switch. The focus of operation and maintenance is on runtime and deployment, and the troubleshooting approach is different from static generators, and the cache directory system cannot be directly transferred over.
Common questions
Q: If the cache validity period is set to -1, will it never fill up the disk?Not at all. -1 only means that the entry will not be cleared due to timeout, but the continuous addition of content will still accumulate usage. The recycling depends on the garbage collection switch during construction, which clears the residual data that is no longer referenced, and it is a separate mechanism from the retention period.
Can only a directory be set for one of the seven types of caches?Yes. The dir and maxAge for each type are independently configured, and it is a common practice to place image processing on a high-speed disk separately, while the rest remain at the default settings, without needing to move the whole thing.
Q: Some caches expire by default after 24 hours, will they be discarded without reuse?The default expiration only affects categories that have not been explicitly adjusted. For caches that are slow to process and infrequently updated, you can extend the retention time individually or set it to -1 for subsequent hits; worry about accumulation and rely on garbage collection switches for regular cleaning.
Q: Does the dynamic system need to be configured according to this?No. AnQiCMS is a dynamic content system based on the Go language, pages are assembled at request time, not generated during the build period, so there is no such build cache and retention time, the focus of operation and maintenance is on runtime and deployment level.