The caching system is opt-in on a per-Datatable basis.

Each Datatable can specify in its Meta options a value for the cache_type option.

Caching Strategies

The possible values are available as constants on datatableview.datatables.cache_types. Regardless of strategy, your Settings will control which Django-defined caching backend to use, and therefore the expiry time and other backend characteristics.


A stand-in for whichever strategy DATATABLEVIEW_DEFAULT_CACHE_TYPE in your Settings specifies. That setting defaults to SIMPLE.


Passes the object_list (usually a queryset) directly to the cache backend for pickling. This is a more faithful caching strategy than PK_LIST but becomes noticeably slower as the number of cached objects grows.


Assumes that object_list is a queryset and stores in the cache only the list of pk values for each object. Reading from the cache therefore requires a database query to re-initialize the queryset, but because that query may be substantially faster than producing the original queryset, it is tolerated.

Because this strategy must regenerate the queryset, extra information on the original queryset will be lost, such as calls to select_related(), prefetch_related(), and annotate().


An explicit option that disables a caching strategy for a table. Useful when subclassing a Datatable to provide customized options.


There are a few project settings you can use to control features of the caching system when activated on a Datatable.



The name of the Django CACHES backend to use. This is where cache expiry information will be specified.



The prefix added to every cache key generated by a table’s get_cache_key() value.


Default:'simple' (datatableview.datatables.cache_types.SIMPLE)

The caching strategy to use when a Datatable’s Meta option cache_type is set to cache_types.DEFAULT.



Controls whether the values that go into the cache key will be hashed or placed directly into the cache key string.

This may be required for caching backends with requirements about cache key length.

When False, a cache key might resemble the following:


When True, the cache key will be a predictable length, and might resemble the following:




When DATATABLEVIEW_CACHE_KEY_HASH is True, setting this to an integer will slice each hash substring to the first N characters, allowing you to further control the cache key length.

For example, if set to 10, the hash-enabled cache key might resemble: