GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - jaemk/cashed: Python - Simple decorator caching

BranchesTags
Open more actions menu

Latest commit

 

History

15 Commits
15 Commits

Folders and files

NameName
Last commit message
Last commit date
cashed
cashed
 
 
examples
examples
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
run_tests.py
run_tests.py
 
 
setup.py
setup.py
 
 

Repository files navigation

python-cashed Build Status PyPI version

Simple caching using decorators

Intallation

pip install cashed

Usage

The cached decorator requires the arguments of the wrapped function to be hashable. cached accepts arguments capacity and seconds to limit the size of the cache and limit age of cached items. cached functions similarly to functools.lru_cache with the addition of the optional time constraint.

import time
from cashed import cached

@cached(capacity=100, seconds=5)
def fib(n):
    if n == 0 or n == 1:
        return n
    return fib(n-1) + fib(n-2)

fib(100)          # -> 354224848179261915075L
fib.cache_info()  # -> {'seconds': 5, 'hits': 98, 'capacity': 100, 'misses': 101, 'size': 100}
time.sleep(5)
fib.cache_info()  # -> {'hits': 98, 'capacity': 100, 'seconds': 5, 'misses': 101, 'size': 0}

About

Python - Simple decorator caching

Topics

cachecachedcachingdecoratorspython

Resources

Readme
MIT license
Activity

Stars

1 star

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.