Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(1)  |  Call(1)  |  Derive(0)  |  Import(0)

        def throttle(cache, key, decrement=1, maximum_stamina=10, regenerate_per_hour=10):

    # Convert the given key into something hashable
    key = "throttle:%s" % sha1(json.dumps(key)).hexdigest()

    # Determine the current stamina
    entry = cache.get(key)
    if (entry == None):
        current_stamina = maximum_stamina
    else:
        current_stamina = min(
            maximum_stamina,
            entry[0] + (datetime.now() - entry[1]).total_seconds() * (regenerate_per_hour / 3600.0)
        )

    # Decrement the current stamina and choke if it's too low
    current_stamina -= decrement
    if (current_stamina < 0):
        raise ActionThrottled(current_stamina + decrement)

    # Note the success by storing the newly decreased stamina
    cache.set(
        key,
        (current_stamina, datetime.now()),
        3600.0 * (maximum_stamina - current_stamina) / regenerate_per_hour
    )
    return current_stamina
        


src/d/j/django-cache-throttle-2012.11.09.3/cache_throttle/decorators.py   django-cache-throttle(Download)
                if request.method in methods or not methods:
                    request.stamina = utils.throttle(
                        cache,
                        key=interpreted_keys,
                        decrement=action_cost,