Skip to main content

microcache

A Really! Small! Cache! for python 2 and 3.

Why?

Working on a totally separate project, I found myself wanting to use [@funcy.memoize](http://funcy.readthedocs.org/en/stable/calc.html#memoize)…a lot. There was a major problem, though: I couldn’t test with it. There was no (obvious) way to turn it off. It was making me crazy, so I spent a few hours writing a small module (even smaller than this, originally) to suit the memoization needs, with a hook to turn it off for testing. When I got to the end of my feature sprint for that project, I decided it made more sense to spin it out into its own project, so here we are!

Current features

  • Simple upsert and get workflow

  • Decorator for “memoization”

  • Enabling and disabling functionality, including a context manager

  • Work directly on the imported module… no additional instantiation

Installation

pip install microcache

Examples

Basic usage

>>> import microcache
>>> microcache.has('key')
False
>>> microcache.get('key', default='default')
'default'
>>> microcache.upsert('key', 'value')
>>> microcache.get('key')
'value'
>>> microcache.disable()
>>> microcache.get('key')

Decorator and context manager

import microcache
import time

@microcache.this
def somefunc():
    time.sleep(5)
    return "this will be cached, and you won't have to wait a second time!"

def test_somefunc():
    somefunc()
    somefunc()
    with microcache.temporarily_disabled():
        # now we'll have to wait again
        somefunc()

Metadata

Release files for microcache 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for microcache 0.1
File Size Uploaded
microcache-0.1.tar.gz 2.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for microcache 0.1
File Interpreter ABI Platform
microcache-0.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 6.5 kB

Release files / microcache-0.1.tar.gz

Download URL microcache-0.1.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f424896f1b1274b3ef64cda89f0e076ab2a313918ac95c298f359a246c2eacfb
BLAKE2b-256 checksum
How to use checksums
2da171dbcd6167c7ff8fd26d56fe6bdefb087a4b9517df184c47f09631a96a75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / microcache-0.1-py2.py3-none-any.whl

Download URL microcache-0.1-py2.py3-none-any.whl
Size 3.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
dc195fde604ddebdb9ddd1be01f6a2576787736506a505c8414384345a8ffe32
BLAKE2b-256 checksum
How to use checksums
4d1c6b02a9a426602dc07e132975f29830505918fc796c5a679aa6e9ba6381ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.0

2 release files

0.4

2 release files

0.3

2 release files

0.2.1

2 release files

0.2

2 release files

This release

0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page