Add cache functionality to Component class
This commit is contained in:
parent
f4210f567b
commit
946bf03190
1 changed files with 4 additions and 0 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
import ast
|
import ast
|
||||||
|
import operator
|
||||||
from typing import Any, ClassVar, Optional
|
from typing import Any, ClassVar, Optional
|
||||||
|
|
||||||
|
from cachetools import TTLCache, cachedmethod
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
|
|
||||||
from langflow.interface.custom.code_parser import CodeParser
|
from langflow.interface.custom.code_parser import CodeParser
|
||||||
|
|
@ -24,9 +26,11 @@ class Component:
|
||||||
field_config: dict = {}
|
field_config: dict = {}
|
||||||
|
|
||||||
def __init__(self, **data):
|
def __init__(self, **data):
|
||||||
|
self.cache = TTLCache(maxsize=1024, ttl=60)
|
||||||
for key, value in data.items():
|
for key, value in data.items():
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
|
|
||||||
|
@cachedmethod(operator.attrgetter("cache"))
|
||||||
def get_code_tree(self, code: str):
|
def get_code_tree(self, code: str):
|
||||||
parser = CodeParser(code)
|
parser = CodeParser(code)
|
||||||
return parser.parse_code()
|
return parser.parse_code()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue