mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-10 13:21:53 +01:00
[rest] Add no-cache
directive to cached REST responses (#3970)
Fixes https://github.com/openhab/openhab-webui/issues/2102. This forces the browser to revalidate the cache every time it is accessed to ensure the data is always fresh. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#directives. This is approach is also suggested in the mdn web docs, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#up-to-date_contents_always. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
This commit is contained in:
parent
b08a01c93f
commit
f5bd7f94f3
@ -188,6 +188,7 @@ public class RuleResource implements RESTResource {
|
||||
.map(rule -> EnrichedRuleDTOMapper.map(rule, ruleManager, managedRuleProvider));
|
||||
|
||||
CacheControl cc = new CacheControl();
|
||||
cc.setNoCache(true);
|
||||
cc.setMustRevalidate(true);
|
||||
cc.setPrivate(true);
|
||||
rules = dtoMapper.limitToFields(rules, "uid,templateUID,name,visibility,description,tags,editable");
|
||||
|
@ -271,6 +271,7 @@ public class ItemResource implements RESTResource {
|
||||
"name,label,type,groupType,function,category,editable,groupNames,link,tags,metadata,commandDescription,stateDescription");
|
||||
|
||||
CacheControl cc = new CacheControl();
|
||||
cc.setNoCache(true);
|
||||
cc.setMustRevalidate(true);
|
||||
cc.setPrivate(true);
|
||||
return Response.ok(new Stream2JSONInputStream(itemStream)).lastModified(lastModifiedDate).cacheControl(cc)
|
||||
|
@ -133,6 +133,7 @@ public class TagResource implements RESTResource {
|
||||
}
|
||||
|
||||
CacheControl cc = new CacheControl();
|
||||
cc.setNoCache(true);
|
||||
cc.setMustRevalidate(true);
|
||||
cc.setPrivate(true);
|
||||
|
||||
@ -165,6 +166,7 @@ public class TagResource implements RESTResource {
|
||||
}
|
||||
|
||||
CacheControl cc = new CacheControl();
|
||||
cc.setNoCache(true);
|
||||
cc.setMustRevalidate(true);
|
||||
cc.setPrivate(true);
|
||||
|
||||
|
@ -328,6 +328,7 @@ public class ThingResource implements RESTResource {
|
||||
}
|
||||
|
||||
CacheControl cc = new CacheControl();
|
||||
cc.setNoCache(true);
|
||||
cc.setMustRevalidate(true);
|
||||
cc.setPrivate(true);
|
||||
thingStream = dtoMapper.limitToFields(thingStream, "UID,label,bridgeUID,thingTypeUID,location,editable");
|
||||
|
@ -168,6 +168,7 @@ public class UIResource implements RESTResource {
|
||||
}
|
||||
|
||||
CacheControl cc = new CacheControl();
|
||||
cc.setNoCache(true);
|
||||
cc.setMustRevalidate(true);
|
||||
cc.setPrivate(true);
|
||||
return Response.ok(new Stream2JSONInputStream(components)).lastModified(lastModifiedDate).cacheControl(cc)
|
||||
|
@ -119,6 +119,7 @@ public class SystemInfoResource implements RESTResource, ConfigurationListener {
|
||||
}
|
||||
|
||||
CacheControl cc = new CacheControl();
|
||||
cc.setNoCache(true);
|
||||
cc.setMustRevalidate(true);
|
||||
cc.setPrivate(true);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user