83030804cc
In relevant requests to the placement API add last-modified and cache-control headers. According the HTTP 1.1 RFC headers last-modified headers SHOULD always be sent and should have a tie to the real last modified time. If we do send them, we need Cache-Control headers to prevent inadvertent caching of resources. This change adds a microversion 1.15 which adds the headers to GET requests and some PUT or POST requests. Despite what it says 'no-cache' means "check to see if the version you have is still valid as far as the server is concerned". Since our server doesn't currently validate conditional requests and will always return an entity, it ends up meaning "don't cache" (which is what we want). The main steps in the patch are: * To both the get single entity and get collection handlers add response.cache_control = 'no-cache' * For single entity add response.last_modified = obj.updated_at or obj.created_at * For collections, discover the max modified time when traversing the list of objects to create the serialized JSON output. In most of those loops an optimization is done where we only check for last-modified information if we have a high enough microversion such that the information will be used. This is not done when listing inventories because the expectation is that no single resource provider will ever have a huge number of inventory records. * Both of the prior steps are assisted by a new util method: pick_last_modfied. Where a time cannot be determined the current time is used. In typical placement framework fashion this has been done in a very explicit way, as it makes what the handler is doing very visible, even though it results in a bit of boilerplate. For those requests that are created from multiple objects or by doing calculations, such as usages and aggregate associations, the current time is used. The handler for PUT /traits is modified a bit more extensively than some of the others: This is because the method can either create or validate the existence of the trait. In the case where the trait already exists, we need to get it from the DB to get its created_at time. We only do this if the microversion is high enough (at least 1.15) to warrant needing the info. Because these changes add new headers (even though they don't do anything) a new microversion, 1.15, is added. Partial-Bug: #1632852 Partially-Implements: bp placement-cache-headers Change-Id: I727d4c77aaa31f0ef31c8af22c2d46cad8ab8b8e |
||
---|---|---|
.. | ||
notes | ||
source |