CACHES configuration Parameters Overview-format
CACHES Dictionary configuration format is as follows
{
' Default ': {
' Backend ':
' Django.core.cache.backends.locmem.LocMemCache ',
}
}
The default cache must be configured when you configure the CACHES dictionary
CACHES configuration Parameters Overview-Backend
Supported backend:
1) ' Django.core.cache.backends.db.DatabaseCache '
2) ' Django.core.cache.backends.dummy.DummyCache '
3) ' Django.core.cache.backends.filebased.FileBasedCache '
4) ' Django.core.cache.backends.locmem.LocMemCache '
5) ' Django.core.cache.backends.memcached.MemcachedCache '
6) ' Django.core.cache.backends.memcached.PyLibMCCache '
Configurable cache back-end list
CACHES Configuration Parameters Overview-Additional parameters
Each cache backend can set additional parameters to control the caching behavior. The following parameters can be configured:
1) TIMEOUT
Cache default expiration time (seconds), 300s (5mins) not set
2) OPTIONS
Optional configuration, different back end, optional configuration options
3) Key_prefix
The default is automatically added to the front of all cache keys
4) VERSION
Default cache keys for version
5) Key_function
Generate final cache function path for keys
Like Locmem, filesystem and database caches implement the cull policy with the following parameters:
Culling policy parameters (options):
Max_entries
Maximum number of allowed in the cache before old data is deleted, default: 300
Cull_frequency
When the number of caches reaches max_entries, a partial cache is deleted, the deletion rate is 1/cull_requency, and if cull_frequency = 2, half of the data is deleted when the max_entries is reached. Default value: 3
CACHES Configuration Parameters Overview-Example
CACHES = {
' Default ': {
' Backend ': ' Django.core.cache.backends.filebased.FileBasedCache ',
' Location ': '/var/tmp/django_cache ',
' TIMEOUT ': 60,
' OPTIONS ': {
' Max_entries ': 1000
}
}
}
Note: Invalid parameters are ignored and do not affect the entire project
How is the caches parameter configured in the Django cache optimization?