diff --git a/Wrappers.cs b/Wrappers.cs index e24681f90b5631e32f7598396b508fec88d306a4..822e8f0e4012f0f55f2cff1edec3b975415a7082 100644 --- a/Wrappers.cs +++ b/Wrappers.cs @@ -68,6 +68,9 @@ abstract partial class StatusBar } } + if(section.Contains("_cache")) + module = new WrapperCache(module, section.Mandatory("_cache").AsMs()); + module.Init(parrent, section); return module; } @@ -145,3 +148,37 @@ class WrapperExec: ModuleWrapper } }).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); + } +} diff --git a/sample.conf b/sample.conf index 4e9906b99297ac4c68665ce8821998ea4b51a9b8..b9edc21338394932e314f83288d6415d9878f044 100644 --- a/sample.conf +++ b/sample.conf @@ -311,6 +311,11 @@ _exec right super shift = osdc "Super+Shift+Right pressed" # <string> # 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: # ========