Code Monkey home page Code Monkey logo

pluca's People

Contributors

flaviovs avatar

Watchers

 avatar  avatar

pluca's Issues

Add decorator to cache function calls

Example:

from pluca.file import create

cache = create()

@cache(max_age=300)  # Cache calls for 5 minutes.
def fast_factorial(n):
    assert n >= 0
    return 1 if n <= 1 else n * fast_factorial(n - 1)

Add easy dynamic cache switching interface

Something like logging.getLogger interface:

import pluca

pluca.add_cache('default', 'pluca.file.create', path='/var/cache/pluca', name='myapp')  # The default cache.
pluca.add_cache('session', 'pluca.memory.create', max_entries=1_000)  # An in-app memory cache.

pluca.basic_config()  # Same as pluca.add_cache('default', 'pluca.file.create', **kwargs)

Then in some module, one could do:

import pluca

# Get default cache.
cache = pluca.get_cache('default')  # Same as pluca.get_cache()

# The the "other" (memory) cache.
session_cache = pluca.get_cache('session')  # Get the "session" (memory) cache

Implement hierarchy in cache interface

Similar to logging:

import pluca.cache

pluca.cache.basic_config()  # Configure "." (aka "root") cache.
pluca.cache.add('foo', ...)
pluca.cache.add('foo.bar', ...)

# Then...
pluca.cache.get('foo.bar')  # Get "foo.bar" cache.
pluca.cache.get('foo.notset')  # Get "foo" cache.
pluca.cache.get('bar')  # Get "root" cache.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.