Cached Queue Mixin
CachedQueueMixin
Overview
CachedQueueMixin allows a widget to request something from the server and the response be cached for future calls
To implement, the widget class needs to set searchUrl. Each instance then calls queueCache() with the specific parameters to be sent to searchUrl. These parameters are used to cache the results, so next time an instance of the widget calls queueCache() with the same parameters, the same response is returned immediately with no server call.
export class MyWidget extends CachedQueueMixin(...) {
protected static searchUrl = "\\EGroupware\\Api\\Etemplate\\Widget\\MyWidget::ajax_check";
constructor() {
...
}
set something(new_something) {
// Do cleanup and validation of new_something ...
// Call cachedQueue for data:
this.cachedQueue({something: new_something}).then((cachedData) => {
// Do what is needed with the cachedData ...
});
}
}
searchUrl should expect an array of parameters, and return the result indexed by the JSON stringification of the parameters:
public function ajax_check(array $parameterList) : array
{
$result = [];
foreach($parameterList as $parameters)
{
...
$result[json_encode($parameters)] = doCheck($parameters) ?? false;
}
Response::get()->data($result);
}
Used by
This mixin is applied by the following widgets.