Skip to main content

Syntactic Cache

Tests codecov PyPI version

Syntactic Cache is a Python library that allows you to automatically create cached properties for methods in your classes, using the syntax of the methods to determine which methods should be cached.

I.e, methods with a given prefix will have a cached property created for them using the method name without the prefix, this allows for easy refactoring of existing code adding cached properties of functions 'for free'. The cache is a simple memory cache linked to each instance of the class.

Installation

You can install Syntactic Cache using pip.

pip install syntactic-cache

Usage

Here's a simple example of how to use the @make_cached_properties decorator.

from syntactic_cache import do_not_make_cached_property, make_cached_properties

@make_cached_properties('get', 'is')
class MyClass:
    def __init__(self, value):
        self.value = value

    def get_power(self, exponent):
        return self.value ** exponent

    def get_square(self):
        return self.get_power(2)

    @do_not_make_cached_property
    def get_cube(self):
        return self.get_power(3)

    def is_even(self):
        return self.value % 2 == 0

instance = MyClass(3)

print(instance.get_square())  # 9, does not use the cache,
print(instance.get_cube())    # 27, does not use the cache.

print(instance.square)  # 9, sets and uses the cache.
print(instance.cube)    # Raises AttributeError, as making cached properties is disabled.
print(instance.power)  # Raises AttributeError, as will not make cached properties for methods with arguments.

print(instance.is_even())  # False, does not use the cache.
print(instance.even)  # False, sets and uses the cache.

Metadata

Release files for syntactic-cache 1.1.0

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

Source distribution (sdist)

Source distribution for syntactic-cache 1.1.0
File Size Uploaded
syntactic_cache-1.1.0.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for syntactic-cache 1.1.0
File Interpreter ABI Platform
syntactic_cache-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.1 kB

Release files / syntactic_cache-1.1.0.tar.gz

Download URL syntactic_cache-1.1.0.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5f51f5e8c275b14e7e957c6f782cbbd3bea262ef55200c73883b81dc2463d418
BLAKE2b-256 checksum
How to use checksums
2737a89ecdb564b9f721ebdcaaddd45faf788c51bbd301c5c1d2e42187d38b59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.7.19

Release files / syntactic_cache-1.1.0-py3-none-any.whl

Download URL syntactic_cache-1.1.0-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7aeee6b3cf1a104d7faf5ba3fc001ec9efd03f10d96bc1500d3b64fe33597e87
BLAKE2b-256 checksum
How to use checksums
72e19ad5665d1ce1a9db2558c8a732dad26cea0ecfa2f02e821e8b33857067dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.7.19

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.1

2 release files

0.1.0

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