Skip to main content

Cache decorator to make applying cache less pain

Project description

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)

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

yoton-0.1.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yoton-0.1.0-py2.7.egg (7.9 kB view details)

Uploaded Egg

File details

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

File metadata

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

File hashes

Hashes for yoton-0.1.0.tar.gz
Algorithm Hash digest
SHA256 450e9e86669422a8d0405c715185fd149d479076898fb3e299eb3c9643ced27f
MD5 cde74074f27bc731c3445ee17d53f607
BLAKE2b-256 57cf235ba392bd993c70289453c0904efabeea60d6cd3d3005b8e0d459117e15

See more details on using hashes here.

File details

Details for the file yoton-0.1.0-py2.7.egg.

File metadata

  • Download URL: yoton-0.1.0-py2.7.egg
  • Upload date:
  • Size: 7.9 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for yoton-0.1.0-py2.7.egg
Algorithm Hash digest
SHA256 2e2422e97f311df7528f9720c2f8fd8ed9f0ff3234b5e170b108a9b9fec65f21
MD5 c71622a00c7432db861d6e82be10bcff
BLAKE2b-256 5ba08302627b4170afbf3703faae29f4641cd5e9147531fd983ff11a8000a546

See more details on using hashes here.

Supported by

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