How to use the ring.lru function in ring

To help you get started, we’ve selected a few ring examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github youknowone / ring / tests / test_func_sync.py View on Github external
    @ring.lru(maxsize=2)
    def f(a, b):
        return a * 100 + b
github youknowone / ring / tests / test_func_sync.py View on Github external
def storage_lru():
    storage = LruCache(128)
    storage.ring = ring.lru
    storage.is_binary = False
    storage.has_has = True
    storage.has_touch = True
    storage.has_expire = False
    return storage
github guardicore / monkey / monkey / monkey_island / cc / models / monkey.py View on Github external
    @ring.lru(
        expire=1  # data has TTL of 1 second. This is useful for rapid calls for report generation.
    )
    @staticmethod
    def is_monkey(object_id):
        try:
            _ = Monkey.get_single_monkey_by_id(object_id)
            return True
        except:
            return False
github guardicore / monkey / monkey / monkey_island / cc / utils.py View on Github external
@lru(maxsize=1)
def local_ip_addresses():
    ip_list = []
    for interface in interfaces():
        addresses = ifaddresses(interface).get(AF_INET, [])
        ip_list.extend([link['addr'] for link in addresses if link['addr'] != '127.0.0.1'])
    return ip_list
github guardicore / monkey / monkey / monkey_island / cc / models / monkey.py View on Github external
    @ring.lru()
    @staticmethod
    def get_label_by_id(object_id):
        current_monkey = Monkey.get_single_monkey_by_id(object_id)
        label = Monkey.get_hostname_by_id(object_id) + " : " + current_monkey.ip_addresses[0]
        if len(set(current_monkey.ip_addresses).intersection(local_ip_addresses())) > 0:
            label = "MonkeyIsland - " + label
        return label
github guardicore / monkey / monkey / monkey_island / cc / models / monkey.py View on Github external
    @ring.lru()
    @staticmethod
    def get_hostname_by_id(object_id):
        """
        :param object_id: the object ID of a Monkey in the database.
        :return: The hostname of that machine.
        :note: Use this and not monkey.hostname for performance - this is lru-cached.
        """
        return Monkey.get_single_monkey_by_id(object_id).hostname
github guardicore / monkey / monkey / monkey_island / cc / utils.py View on Github external
@lru(maxsize=1)
def get_subnets():
    subnets = []
    for interface in interfaces():
        addresses = ifaddresses(interface).get(AF_INET, [])
        subnets.extend([ipaddress.ip_interface(link['addr'] + '/' + link['netmask']).network for link in addresses if link['addr'] != '127.0.0.1'])
    return subnets