ODataModel $metadata Cache issue
OpenUI5 version: All
Browser/version (+device/version): All
Any other tested browsers/devices(OK/FAIL):
URL (minimal example if possible):
User/password (if required and possible - do not post any confidential information here):
Steps to reproduce the problem:
- The OData service definition is changed in SAP transaction SEGW which results in a new $metadata document
- The UI5 application using v2.ODataModel requests the service $metadata document without any request headers relating to cache. 3.
What is the expected result?
The changed $metadata document should be retrieved from the server instead of relying on the one cached previously by the browser
What happens instead?
The browser doesn't even check with the server if there's an updated $metadata document but uses the possibly outdated one from its browser cache. Result: http 200 (from disk cache)
Any other information? (attach screenshot if possible)
My workaround is to add custom headers Cache-control: max-age=0 when instantiating the ODataModel
var oModel = new ODataModel(serviceUrl, {
json: true,
maxDataServiceVersion: '2.0',
defaultCountMode: CountMode.Inline,
defaultBindingMode: BindingMode.TwoWay,
headers: { 'Cache-Control': 'max-age=0' }
Then the browser automatically adds the If-None-Match header with the eTag of the cached document and the If-Modified-Since header with the last-modified date of the cached document to tell the server to return the document only if it's newer then the one which is already available in the browser cache. In most cases the cached document is the most recent one and thus this request only takes ca. 400 bytes. If the document was updated meanwhile the server will return it to the browser.
I would expect this to happen as default behavior of the ODataModel implementation. Why do I need to add this header myself?
I also read about Cache Buster for OData Metadata of SAP Fiori Apps and I ask myself why is this even necessary? It would be sufficient to add this simple http header to the ODataModel requests by the UI5 library instead of introducing a complete cachebuster mechanism for metadata instead.
I would appreciate an explanation on the rationale behind this.
Regards, Frank
Hello @Frank683 ,
I've created an internal incident 1870102016. And the colleagues will comment here in GitHub.
Regards, Gery
Hello @Frank683,
the caching behavior should be controlled by the service. If the response contains the necessary cache control headers everything works fine and there is no need to add any header for the request.
BR, Jan
Hi @loginger ,
if this is the solution then which exactly are "the necessary cache control headers" ? And how do we configure this behavior in SAP Gateway?
And besides that: What's the reason behind Cache Buster for OData Metadata of SAP Fiori Apps then?
Regards, Frank
Hi @Frank683, sorry, but I can't tell you how to configure that in gateway. I think you need to talk to some GW people. The cache headers are well specified https://tools.ietf.org/html/rfc7234. You have to judge about the correct strategy. The reason for the Fiori App cache busting is the following: The client does not know about changes in metadata, but we want to cache the metadata in the browser cache. To get that done the backend provides us a cache buster token we add as query parameter to the metadata url. If we do so the backend response contains cache headers so the browser puts the metadata document into the cache. When the metadata changes at the backend we get a new token. A token change will invalidate the browser cache. BR, Jan
@loginger
Thanks for the explanation. That's the same mechanism as the UI5 App Cache Buster, which I use for our applications.
For the $metadata I'll stay with my approach adding the max-age=0 request header since this makes the browser check for a new $metadata document on every application start and the server will answer with a 304 not modified in most cases which will cost only 0,5 KB at most.
Regards, Frank