Projects:Static Resources Caching/Specs
To know more about how Openbravo processes the code of the static resources, see here.
Keeping this is mind, a new class will be created in core: StaticResourceProvider. This class will allow to keep the information needed to cache the static resources for the different applications like the ERP, WebPOS and other mobile applications.
Note that before this project the file is generated once (having no modules in in development status) but the file name is computed in every request to the StaticResourceComponent.
After the first successful login, with the new cache mechanism both request will be avoided:
- When requesting the file, as it has already been requested before, the browser will retrieve it using its own memory cache avoiding this second request.
This mechanism is similar to the one being used in WebPOS module, with the MobileStaticResourceComponent class. For this reason, this class will be refactored to make use of the StaticResourceProvider. Thus, all the components providing static resources will be using a common caching infrastructure.
Caching CSS resources
One slight difference is that this component does not generate a file but returns a string with all the content. Thus, in order to cache this content with the browser the Etag in the header of the request to the component is used.
Before this project, the Etag is based on the module versions when there are no modules in in development status. In other case a random value is generated, i.e., cache is prevented.
Two modifications will be applied to this component, when there are no modules in in development status:
- The css content will be cached using the StaticResourceProvider. This way they will be computed once, on the first successful login.
- The Etag will be computed based on the css content by computing its corresponding MD5 hash.
Invalidating the Cache
In case it is necessary to invalidate the cache of the StaticResourceProvider class one of the following alternatives can be taken:
- Restart Tomcat
- Invalidate the information of a particular static resource using a JMX agent.
Regarding this second alternative, it is possible because the StaticResourceProvider has been declared as a MBean. Together with this, the new OBManagementFactory class is available which provides an API to register MBeans by using the MBean server.