akvo.cache.prepo module

class akvo.cache.prepo.PrePoPickler[source]

Bases: object

Helps prepare an object pre-pickle and an object post-pickle

Some objects take an inordinate amount of time to pickle, which negates the benefits of caching. In some cases however, it can help to pickle only certain parts of the object from whence the entire object

can then later be built at a lower cost.

classmethod expand(obj: Any) Any[source]

Recreate the stored object from its reduced state

classmethod reduce(obj: Any) Any[source]

Make a smaller version of the object to be stored

class akvo.cache.prepo.QuerysetPrePo[source]

Bases: PrePoPickler

The queryset’s model and SQL query are pickled instead of the results from the executed query.

(Un-)Pickling speed of Querysets is very unstable. It can often be more expensive to pickle and unpickle than simply execute it.

In cases where building the queryset itself is expensive, it can be worth caching the resulting queryset.

classmethod expand(reduction: QuerysetReduction) QuerySet[source]

Rebuilds a fresh Queryset from a reduction

classmethod reduce(queryset: QuerySet) QuerysetReduction | None[source]

Extracts the full, importable path of the Queryset’s model + the SQL query

class akvo.cache.prepo.QuerysetReduction(model_name: str, query: Query)[source]

Bases: object

The important parts of a Queryset that allow it to be rebuilt

model_name: str
query: Query