forked from p15670423/monkey
Using `ring` as the primary caching library, no functools.
Lowers amount of deps
This commit is contained in:
parent
93c9aaa513
commit
4d9467bac9
|
@ -89,16 +89,14 @@ class Monkey(Document):
|
||||||
|
|
||||||
# TODO This is not a field therefore cache shouldn't be here
|
# TODO This is not a field therefore cache shouldn't be here
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ring.lru(coder=ring.coder.JsonCoder())
|
@ring.lru()
|
||||||
def get_label_by_id(object_id):
|
def get_label_by_id(object_id):
|
||||||
print("Actually in get_label_by_id - not cached for {}".format(str(object_id)))
|
|
||||||
current_monkey = Monkey.get_single_monkey_by_id(object_id)
|
current_monkey = Monkey.get_single_monkey_by_id(object_id)
|
||||||
return Monkey.get_hostname_by_id(object_id) + " : " + current_monkey.ip_addresses[0]
|
return Monkey.get_hostname_by_id(object_id) + " : " + current_monkey.ip_addresses[0]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ring.lru(coder=ring.coder.JsonCoder())
|
@ring.lru()
|
||||||
def get_hostname_by_id(object_id):
|
def get_hostname_by_id(object_id):
|
||||||
print("Actually in get_hostname_by_id - not cached for {}".format(str(object_id)))
|
|
||||||
return Monkey.get_single_monkey_by_id(object_id).hostname
|
return Monkey.get_single_monkey_by_id(object_id).hostname
|
||||||
|
|
||||||
def set_hostname(self, hostname):
|
def set_hostname(self, hostname):
|
||||||
|
|
|
@ -6,11 +6,7 @@ import array
|
||||||
import struct
|
import struct
|
||||||
import ipaddress
|
import ipaddress
|
||||||
from netifaces import interfaces, ifaddresses, AF_INET
|
from netifaces import interfaces, ifaddresses, AF_INET
|
||||||
|
from ring import lru
|
||||||
try:
|
|
||||||
from functools import lru_cache
|
|
||||||
except ImportError:
|
|
||||||
from backports.functools_lru_cache import lru_cache
|
|
||||||
|
|
||||||
__author__ = 'Barak'
|
__author__ = 'Barak'
|
||||||
|
|
||||||
|
@ -56,8 +52,8 @@ else:
|
||||||
# The local IP addresses list should not change often. Therefore, we can cache the result and never call this function
|
# The local IP addresses list should not change often. Therefore, we can cache the result and never call this function
|
||||||
# more than once. This stopgap measure is here since this function is called a lot of times during the report
|
# more than once. This stopgap measure is here since this function is called a lot of times during the report
|
||||||
# generation.
|
# generation.
|
||||||
# This means that if the interfaces of the Island machines change, the Island process needs to be restarted.
|
# This means that if the interfaces of the Island machine change, the Island process needs to be restarted.
|
||||||
@lru_cache(maxsize=1)
|
@lru(maxsize=1)
|
||||||
def local_ip_addresses():
|
def local_ip_addresses():
|
||||||
ip_list = []
|
ip_list = []
|
||||||
for interface in interfaces():
|
for interface in interfaces():
|
||||||
|
@ -66,7 +62,11 @@ def local_ip_addresses():
|
||||||
return ip_list
|
return ip_list
|
||||||
|
|
||||||
|
|
||||||
@lru_cache(maxsize=1)
|
# The subnets list should not change often. Therefore, we can cache the result and never call this function
|
||||||
|
# more than once. This stopgap measure is here since this function is called a lot of times during the report
|
||||||
|
# generation.
|
||||||
|
# This means that if the interfaces or subnets of the Island machine change, the Island process needs to be restarted.
|
||||||
|
@lru(maxsize=1)
|
||||||
def get_subnets():
|
def get_subnets():
|
||||||
subnets = []
|
subnets = []
|
||||||
for interface in interfaces():
|
for interface in interfaces():
|
||||||
|
|
|
@ -26,5 +26,4 @@ mongoengine
|
||||||
mongomock
|
mongomock
|
||||||
requests
|
requests
|
||||||
dpath
|
dpath
|
||||||
backports.functools-lru-cache
|
|
||||||
ring
|
ring
|
||||||
|
|
Loading…
Reference in New Issue