traffic.core.cache

traffic.core.cache.cache_results(fun=None, cache_directory=PosixPath('.'), loader=<function read_pickle>, pd_varnames=False)

The point of this method is to be able to cache results of some costly functions on pd.DataFrame, Flight or Traffic structures.

Decorate your function with the cache_results method and go ahead!

Parameters:
  • fun (Optional[Callable[..., TypeVar(T, DataFrame, Traffic, Flight)]]) – the function to decorate

  • cache_directory (Path) – (default: current directory) where to store the results

  • loader (Callable[[Path], TypeVar(T, DataFrame, Traffic, Flight)]) – (default: pd.read_pickle()) the function used to load the data from a cache file

  • pd_varnames (bool) – (default: False) when True, try to use the name of the local variable as a cache key

Return type:

Callable[[Callable[..., TypeVar(T, DataFrame, Traffic, Flight)]], Union[TypeVar(T, DataFrame, Traffic, Flight), Callable[..., TypeVar(T, DataFrame, Traffic, Flight)]]]

traffic.core.cache.property_cache(method)

Computes attribute value and caches it in the instance.

Reference: Python Cookbook (Denis Otkidach)

This decorator allows you to create a property which can be computed once and accessed many times. Sort of like memoization, but by instance.