Skip to content

Commit

Permalink
First test of caching on tags manager.
Browse files Browse the repository at this point in the history
  • Loading branch information
userwiths committed Aug 12, 2021
1 parent e557678 commit 8f77eea
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 24 deletions.
18 changes: 0 additions & 18 deletions cache.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 15 additions & 0 deletions declaration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from functools import wraps
from core import Factory,ConfigAdvanced

class VNode:
Expand All @@ -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()
6 changes: 2 additions & 4 deletions tags/csv/tag_manager.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions tags/custom/tag_manager.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down

0 comments on commit 8f77eea

Please sign in to comment.