Skip to content

Commit bcfa8f9

Browse files
committed
chaching
1 parent 34552b0 commit bcfa8f9

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

pyhdx/web/cache.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import param
2+
3+
4+
class Cache(param.Parameterized):
5+
pass
6+
7+
8+
class MemoryCache(param.Parameterized):
9+
10+
_cache = param.Dict(default={})
11+
12+
def __getitem__(self, item):
13+
return self._cache.get(item)
14+
15+
def __setitem__(self, key, value):
16+
self._cache[key] = value

pyhdx/web/sources.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ def get(self):
2323

2424
class TableSource(Source):
2525

26-
tables = param.Dict({})
26+
tables = param.Dict(
27+
default={},
28+
doc="Dictionary of tables (pd.DataFrames)")
29+
30+
hashes = param.Dict(
31+
default={},
32+
doc="Dictionary of table hashes")
2733

2834
_type = 'table'
2935

pyhdx/web/transforms.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class Transform(param.Parameterized):
2121

2222
redrawn = param.Event(doc="event gets triggered when widgets are changed and the controller needs to redraw them")
2323

24+
cache = param.ClassSelector(class_=Cache)
25+
2426
def __init__(self, **params):
2527
super().__init__(**params)
2628

@@ -53,6 +55,12 @@ def get(self):
5355
df = self.source.get_table(self.table) # returns None on KeyError #todo change to source.get_table
5456
return df
5557

58+
@property
59+
def hash(self):
60+
# or sources can have multiple hashes?
61+
# / objects can have multiple hashes?
62+
return tuple([self._type, self.table, self.source.hashes[self.table]])
63+
5664
@param.depends('table', watch=True)
5765
def _table_updated(self):
5866
self.updated = True

0 commit comments

Comments
 (0)