Skip to main content

A python memoisation framework

Project description

Build Status Coverage

A python memoisation framework.

Unlike other well known examples, uses run time tracing instead of parsing or meta-evaluation to build up a directed acyclic graph of function dependencies.

Unloading values from the cache must be done explicitly but is made easier by support for nested cache contexts.

Dug supports manually changing the return value of tracked functions for certain parameters.

Dug stands for directed un-cyclic graph. I know un-cyclic isn’t a real word.

Installation

Dug can be installed from pypi

Getting started

Components

Cache:
  • Created on entering a context

  • Populated with tweaks from the owning context

  • No support for rebuilding on top of a parent cache, must be recreated from tweaks stored in the context.

  • Should not forward changes on to parent cache. Nodes in parent cache that have different values from what they would in the child cache should be marked as masked.

Identifying nodes

Node identifiers must be serializable. It probably makes sense for node identifiers to just hold a reference to the function and rely on pickle or whatever to deal with the wire format.

Stacked contexts, tweaking, and cache invalidation

The rules: Tweaked nodes are masked. Nodes depending on masked nodes are also masked. Nodes marked as masked should not be fetched from the parent context. The results of nodes marked as masked should be stored in the current context’s cache. Nodes can be marked as masked and stored in the cache. Nodes can be marked as masked and not stored in the cache.

Tweaking a node:

When tweaking a node it is necessary to mark all of its descendants as masked. This can be done recursively. On encountering a node that is already marked as masked, it can be assumed that all of its descendants are also marked as masked. This means that it is not necessary to recurse past it.

Re-entering a context:

It is possible that on re-entering a context, the parent context will have changed. It will probably always be necessary to re-tweak all nodes in the context.

Some part of the cache will have to be invalidated to account for changes in the new parent. It might be possible to invalidate only the parts marked masked in the parent context. It might make sense to always clear the cache on exiting the context no matter what. This would allow contexts to be used as a way to avoid excessive caching.

Garbage collection

It has been suggested that garbage collection is probably not actually necessary. Instead rely on discarding contexts to get granular control over what stuff to keep.

Questions

  • Is there a way to split tweaking from caching?

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dug-0.1.0.tar.gz (4.9 kB view details)

Uploaded Source

File details

Details for the file dug-0.1.0.tar.gz.

File metadata

  • Download URL: dug-0.1.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for dug-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1446438f5ac8dde1cc40b56420c57548dc620a2547ed8a44eb606a61456d7b4c
MD5 d721724014c4fd185dea611b904429e6
BLAKE2b-256 bfddedafeed7429eebd7e45b87465be90b027715f426319195a5b86c9a907a51

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page