cache

fbf cache provding get, set and delete functions.

fbf.lib.cache.delete(name, namespace='')

delete data from the cache.

fbf.lib.cache.get(name, namespace='')

get data from the cache.

fbf.lib.cache.set(name, item, timeout=0, namespace='')

set data in the cache.

fbf.lib.cache.size()

CODE

# fbf/cache.py
#
#

""" fbf cache provding get, set and delete functions. """

fbf imports

from fbf.utils.lazydict import LazyDict

basic imports

import logging

defines

cache = LazyDict()

functions

def get(name, namespace=""):
    """ get data from the cache. """
    global cache
    try:
        #logging.debug("cache - returning %s" % cache[name])
        return cache[name]
    except KeyError: pass

def set(name, item, timeout=0, namespace=""):
    """ set data in the cache. """
    #logging.debug("cache - setting %s to %s" % (name, str(item)))
    global cache
    cache[name] = item

def delete(name, namespace=""):
    """ delete data from the cache. """
    try:
        global cache
        del cache[name]
        logging.warn("cache - deleted %s" % name)
        return True
    except KeyError: return False

def size():
    return len(cache)

Table Of Contents

Previous topic

botbase

Next topic

callbacks

This Page