Skip to main content

Cache data which access frequently

Project description

k3cacheable

Action-CI Documentation Status Package

Cache data which access frequently.

k3cacheable is a component of pykit3 project: a python3 toolkit set.

Cache data which access frequently.

Install

pip install k3cacheable

Synopsis

import k3cacheable
import time

# create a `LRU`, capacity:10 timeout:60
c = k3cacheable.LRU(10, 60)

# set value like the `dict`
c['key'] = 'val'

# get value like the `dict`
# if item timeout, delete it and raise `KeyError`
# if item not exist, raise `KeyError`
try:
    val = c['key']
except KeyError:
    print('key error')

cache_data = {
    'key1': 'val_1',
    'key2': 'val_2',
}

# define the function with a decorator
@k3cacheable.cache('cache_name', capacity=100, timeout=60,
                 is_deepcopy=False, mutex_update=False)
def get_data(param):
    return cache_data.get(param, '')

# call `get_data`, if item has not been cached, cache the return value
data = get_data('key1')

# call `get_data` use the same param, data will be got from cache
time.sleep(1)
data = get_data('key1')

# if item timeout, when call `get_data`, cache again
time.sleep(1)
data = get_data('key1')

# define a method with a decorator
class MethodCache(object):

    @k3cacheable.cache('method_cache_name', capacity=100, timeout=60,
                     is_deepcopy=False, mutex_update=False)
    def get_data(self, param):
        return cache_data.get(param, '')

mm = MethodCache()
data = mm.get_data('key2')

Author

Zhang Yanpo (张炎泼) drdr.xp@gmail.com

Copyright and License

The MIT License (MIT)

Copyright (c) 2015 Zhang Yanpo (张炎泼) drdr.xp@gmail.com

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

k3cacheable-0.1.2.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

k3cacheable-0.1.2-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file k3cacheable-0.1.2.tar.gz.

File metadata

  • Download URL: k3cacheable-0.1.2.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for k3cacheable-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6fcc7d3904b62e3bf9f3e4def5cb7320977fa351bc32392ba446256c4ffae992
MD5 be782e373f4f23dd92983321fbd1cbcd
BLAKE2b-256 07627e5be932c6b262c53863222fa0fb3dc4d07d09c04f4bb24ad3b903bec2ba

See more details on using hashes here.

File details

Details for the file k3cacheable-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: k3cacheable-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for k3cacheable-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 715a2fb4765f20865dd637ab309f72f22322b737dc613a7b7ec599da347ecfde
MD5 a7107e76ebecace7d9c7ecf615d5bae8
BLAKE2b-256 cd6b56fddfb1afd131bcb149b8017d0c8c299b978f35dd94a9608ced92e93176

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