From 8f77eea01437352baafe07c9f95c3f0d0076225f Mon Sep 17 00:00:00 2001 From: Stiliyan Tonev Date: Thu, 12 Aug 2021 13:16:25 +0300 Subject: [PATCH] First test of caching on tags manager. --- cache.py | 18 ------------------ declaration.py | 15 +++++++++++++++ tags/csv/tag_manager.py | 6 ++---- tags/custom/tag_manager.py | 3 +-- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/cache.py b/cache.py index 8aaffc9..95f62b7 100644 --- a/cache.py +++ b/cache.py @@ -1,21 +1,3 @@ -from functools import wraps - -cache=[ - {'name':'TagManager','method':'load_tags','store':None}, - {'name':'IndexManager','method':'load_files','store':None}, - {'name':'TagManager','method':'load_tags','store':None} -] - -def invalidate(func): - @wraps(func) - def execute_and_invalidate(*args, **kwargs): - func(*args, **kwargs) - print(dir(func)) - print("Module: "+func.__module__) - print("Class: "+func.__class__.__name__) - print("Name: "+func.__name__) - return execute_and_invalidate - class CacheRecord: def __init__(self,name,method): self.name=name diff --git a/declaration.py b/declaration.py index 10cfffa..7d61c99 100644 --- a/declaration.py +++ b/declaration.py @@ -1,4 +1,5 @@ import re +from functools import wraps from core import Factory,ConfigAdvanced class VNode: @@ -16,5 +17,19 @@ def build(self,data): return self +cache=[ + {'name':'TagManager','method':'load_tags','store':None}, + {'name':'IndexManager','method':'load_files','store':None}, + {'name':'TagManager','method':'load_tags','store':None} +] + +def invalidate(func): + @wraps(func) + def execute_and_invalidate(*args, **kwargs): + func(*args, **kwargs) + print(factory.getInstanceByName('TagManager').load_tags()) + print('\n') + return execute_and_invalidate + factory=Factory() config=ConfigAdvanced() \ No newline at end of file diff --git a/tags/csv/tag_manager.py b/tags/csv/tag_manager.py index e52912c..0c368f7 100644 --- a/tags/csv/tag_manager.py +++ b/tags/csv/tag_manager.py @@ -1,8 +1,6 @@ import csv import sympy -from declaration import config, factory -from cache import invalidate -from functools import lru_cache +from declaration import config, factory, invalidate class TagManager: def __init__(self): @@ -21,8 +19,8 @@ def get_tags(self): return self.available_tags - @lru_cache(maxsize=4) def load_tags(self): + self.tags=[] path=self.tags_file with open(path,newline='') as csvfile: diff --git a/tags/custom/tag_manager.py b/tags/custom/tag_manager.py index c3174fb..555e854 100644 --- a/tags/custom/tag_manager.py +++ b/tags/custom/tag_manager.py @@ -1,5 +1,4 @@ -from declartaion import config, factory -from functools import lru_cache +from declartaion import config, factory,invalidate class TagManager: def __init__(self):