-
-
Notifications
You must be signed in to change notification settings - Fork 14
Cache
ACE comes with in-built functionality of caching mechanism, which is an opt-out feature. Cache is used internally for reusing some data for the next runs, and depending on used cache provider, its behavior might change slightly. Currently ACE uses caching mechanism to preload previous What If API responses and VM capabilities (used for inferring OS disks sizes).
Below you can find detailed instruction of how use any of the available providers.
Local cache provider saves cached What If responses as files in the working directory of ACE. Each response is saved as a separate .cache
file named as <cache-key>.cache
.
ACE uses
.ace
directory to store cached items. User running ACE must have permissions to create that directory and files inside it.
Local cache is meant for scenarios, where agent or machine filesystem is preserved between multiple runs of your pipeline. It won't provide any benefits in scenarios where filesystem gets recreated.
It's possible to use Azure Storage as cache storage in order to leverage that feature on ephemeral environments (i.e. CICD agents). To use Azure Storage as cache you need to meet some prerequisites:
- principal running ACE must have access to Azure Storage account
- the access to storage account must be granted via RBAC
- the role assigned to a principal must give it possibility to create containers & create blobs
The easiest way to grant access working with Azure Storage cache feature is assigning Storage Blob Data Contributor role to a principal.
You also need to tell ACE to use Azure Storage as cache location. To do that, use two additional options when running ACE:
./azure-cost-estimator <template-path>.json|.bicep <subscription-id> <resource-group> \
...options... \
--cache-handler "AzureStorage" \
--cache-storage-account-name "<storage-account-name>"
When you run your estimation, ACE will create a container named acecache
and will start putting there cache files depending on the data provided by your templates.
Cache key is calculated automatically for each cached item. Some items will have static keys (e.g. VM capabilities), while other will have dynamically calculated keys depending on a set of values.
Cache key is calculated as SHA1 hash based on the following values:
- scope ID
- resource group name (if available)
- template content
- parameters values (both inline and from parameters file)
This means, that if you want to invalidate cache, you have two options:
- you modify any of the values used to calculate cache key
- you pass
--disable-cache
flag when running ACE
ACE is unaware of any changes in your cloud infrastructure meaning if there were any changes related to your infrastructure, which might have impacted calculation, you should either include them in your template, or invalidate local cache before performing calculation.
Note, that passing
--disable-cache
won't remove local cache. When you run ACE without that flag, previously created cache keys will still be in your local filesystem meaning they can be reused. Future releases of ACE may introduce different behavior or separate option for refreshing local cache storage. By that time, a workaround is to remove.ace
directory.