Skip to main content

YoTon

https://travis-ci.org/ivannotes/yoton.svg?branch=master

YoTon is an util for cache, it simplifies cache with a decorator.

Install

$ pip install yoton

Configuration

redis_server_config = {
    "default": {
        "host": "localhost",
        "port": 6379,
        "db": 1
    },
    "server_a": {
        "host": "localhost",
        "port": 6378,
        "db": 2,
    }
}
yoton = YoTon(redis_server_config)

Apply To Function

@yoton.cache(key_pattern="dummy_cache_key", expire_seconds=60)
def dummy_func():
    return "hello"

>> dummy_func()  # call the function
"hello" set in the cache

Key Pattern

The cache key is using python’s string format syntax, you can find it here

@youton.cache(key_pattern="dummy:{a}_{b}_{c}", expire_seconds=60)
def dummy_func_with_params(a, b, c=3):
    return a + b + c

Complex object in parameters

@youton.cache(key_pattern="dummy:{a.id}_{b.name}", expire_seconds=60)
def dummy_func_with_params(a, b):
    return a + b

Select Database

@yoton.cache(key_pattern="dummy_cache_key", database="test", expire_seconds=60)
def dummy_func_database():
    return "hello"

Customized Formatter

@yoton.cache(key_pattern="dummy_cache_key", key_formatter=CustomizedFormatter(), expire_seconds=60)
def dummy_func_keyforamtter():
    pass

Apply Cache To Instance Method

class DummyClass(object):

    @yoton.cache(key_pattern="instance_method")
    def instance_method(self):
        return "hello"

Misc

# call the function directly without touch cache
dummy_func_with_params.call(a=1, b=2, c=3)

# refresh cache data
dummy_func_with_params.refresh_cache(a=1, b=2, c=3)

# remove data in cache
dummy_func_with_params.delete_cache(a=1, b=2, c=3)

Metadata

Release files for yoton 0.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 yoton 0.1.0
File Size Uploaded
yoton-0.1.0.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yoton 0.1.0
File Interpreter ABI Platform
yoton-0.1.0-py2.7.egg Legacy Egg format - - Details

Total release size: 12.0 kB

Release files / yoton-0.1.0.tar.gz

Download URL yoton-0.1.0.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
450e9e86669422a8d0405c715185fd149d479076898fb3e299eb3c9643ced27f
BLAKE2b-256 checksum
How to use checksums
57cf235ba392bd993c70289453c0904efabeea60d6cd3d3005b8e0d459117e15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / yoton-0.1.0-py2.7.egg

Download URL yoton-0.1.0-py2.7.egg
Size 7.9 kB
Tags Egg
SHA-256 checksum
How to use checksums
2e2422e97f311df7528f9720c2f8fd8ed9f0ff3234b5e170b108a9b9fec65f21
BLAKE2b-256 checksum
How to use checksums
5ba08302627b4170afbf3703faae29f4641cd5e9147531fd983ff11a8000a546
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.0 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