Beispiel #1
0
def make_cacheable(func):
    from bae.api.memcache import BaeMemcache
    cache = BaeMemcache()
    def wrap(*args, **kwargs):
        key = '%s %s' % (','.join(str(x) for x in args), ','.join('%s:%s' % (k, v) for k, v in kwargs.items()))
        value = cache.get(key)
        if value is None:
            value = func(*args, **kwargs)
            cache.set(key, value, 86400)
        return value
    return wrap
Beispiel #2
0
            BAE_BCS.del_object(BUCKET_NAME, object_name)
            raise Exception(resp)

    url = urljoin(BCS_HOST, BUCKET_NAME) + object_name
    return url, url


def delete_file(file_path):
    from urlparse import urlsplit
    from settings import BAE_BCS

    path = urlsplit(file_path).path
    _, bucket_name, object_name = path.split("/", 2)
    object_name = "/" + object_name

    err, resp = BAE_BCS.del_object(bucket_name, object_name)
    if err != 0:
        raise Exception(resp)


############################################
## memcache
############################################
from settings import ENABLE_MEMCACHE

if ENABLE_MEMCACHE:
    from bae.api.memcache import BaeMemcache

    memcache = BaeMemcache()  # bind memcache to BAE
    memcache.flush_all = lambda cls: None