Skip to main content

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

Why?

Working on a totally separate project, I found myself wanting to use funcy.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.2

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.2
File Size Uploaded
microcache-0.2.tar.gz 3.0 kB Details

Built distribution (wheel)

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

Total release size: 6.6 kB

Release files / microcache-0.2.tar.gz

Download URL microcache-0.2.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e1e16f372b5e7ff5b5f4c9aecd838b70293cb11eaaba6e582817c1f4c1776aba
BLAKE2b-256 checksum
How to use checksums
ba227ad7d9e4fb0cc527d96fa2f65f28c39ac6404917b1c396bf7c9f4f731bb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL microcache-0.2-py2.py3-none-any.whl
Size 3.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
73671fbfcc9abd10894df91b353514f3039c8feeb1f27d81b5e522059d4c7d87
BLAKE2b-256 checksum
How to use checksums
77b38418a35bfeb539a3a7121be7391a79d0bd7f5d5658e504a8704298c5ec9a
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

This release

0.2 This release

2 release files

0.1

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