Skip to content
Snippets Groups Projects
Commit 8ad9e862 authored by Jiří Kalvoda's avatar Jiří Kalvoda
Browse files

Wrappers: Cache

parent 6763a956
No related branches found
No related tags found
No related merge requests found
...@@ -68,6 +68,9 @@ abstract partial class StatusBar ...@@ -68,6 +68,9 @@ abstract partial class StatusBar
} }
} }
if(section.Contains("_cache"))
module = new WrapperCache(module, section.Mandatory("_cache").AsMs());
module.Init(parrent, section); module.Init(parrent, section);
return module; return module;
} }
...@@ -145,3 +148,37 @@ class WrapperExec: ModuleWrapper ...@@ -145,3 +148,37 @@ class WrapperExec: ModuleWrapper
} }
}).ToArray(); }).ToArray();
} }
class WrapperCache: ModuleWrapper
{
IEnumerable<Block> data;
long? dataTime_ms;
long maxOld_ms;
bool wantRedraw = false;
public WrapperCache(Module _child, long _maxOld_ms):base(_child)
{
maxOld_ms = _maxOld_ms;
}
override public IEnumerable<Block> Get()
{
lock(this)
if(wantRedraw)
{
data = null;
dataTime_ms = null;
}
child.Get();
if(dataTime_ms == null || dataTime_ms + maxOld_ms <= Environment.TickCount64)
{
dataTime_ms = Environment.TickCount64;
data = child.Get();
}
return data;
}
override public void Schedule(int in_ms)
{
lock(this)
wantRedraw = true;
parent.Schedule(in_ms);
}
}
...@@ -311,6 +311,11 @@ _exec right super shift = osdc "Super+Shift+Right pressed" ...@@ -311,6 +311,11 @@ _exec right super shift = osdc "Super+Shift+Right pressed"
# <string> # <string>
# Command to run # Command to run
_cache = 10
# <time>
# Fetch data from module only once per this time.
# Note that visible data couldn't be more than (_cache + refresh) old.
# Parsers: # Parsers:
# ======== # ========
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment