# Invalidate cache on every build/deploy/startup?

**URL:** <https://forum.litium.com/t/invalidate-cache-on-every-build-deploy-startup/1323>\
**Category:** Questions\
**Created:** [February 11, 2020, 10:39am UTC](https://forum.litium.com/t/invalidate-cache-on-every-build-deploy-startup/1323 "2020-02-11T10:39:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robin.w](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/robin.w/32/75_2.png) [@Robin.w](https://forum.litium.com/u/Robin.w)\
**Post date:** [February 11, 2020, 10:39am UTC](https://forum.litium.com/t/invalidate-cache-on-every-build-deploy-startup/1323/1 "2020-02-11T10:39:03Z")

</div>

I am loading some parts of my css into a lazy cache, and provide a cache key, is there a / what type of variable/id is best to use for the cache key to invalidate on every build or startup?  
Litium version: 7.3

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [February 11, 2020, 12:28pm UTC](https://forum.litium.com/t/invalidate-cache-on-every-build-deploy-startup/1323/2 "2020-02-11T12:28:12Z")

</div>

In general the css/js that should be loaded should have a version query-string parameter to make it the url unique for each change. The Litium `FingerprintExtension.ContentFingerprint` extensions method are doing this and calculating an hash of the content in the file.

if that not solves your question I need to have little more information about how your setup is working to see if I can find another solution.

---

<div class="post-metadata">

**Author:** ![Robin.w](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/robin.w/32/75_2.png) [@Robin.w](https://forum.litium.com/u/Robin.w)\
**Post date:** [February 11, 2020, 2:23pm UTC](https://forum.litium.com/t/invalidate-cache-on-every-build-deploy-startup/1323/3 "2020-02-11T14:23:08Z")

</div>

We are doing this in the HeadViewModelBuilder and we cache it so we don’t touch the file on disk, but dose the fingerprint read the file on every pageview?

```
	private string BuildCriticalCss(WebsiteModel websiteModel)
	{

		if (websiteModel.Website.IsElevenWebsite())
		{
			var cachingService = new CachingService();
			var path = HttpContext.Current.Server.MapPath("/ui/Eleven/css/site.min.css");
			string cacheKey = $"css_" + FingerprintExtension.ContentFingerprint(path);
			return cachingService.GetOrAdd(cacheKey, () => GetCss(path), DateTimeOffset.UtcNow.AddMinutes(60 * 24));
		}
		return "";
	}

	private string GetCss(string filePath){
			return File.ReadAllText(filePath);
	}

```

If the fingerprint reads the file on disk, this might be just as effetive? @Html.Raw(File.ReadAllText(Server.MapPath("/ui/Eleven/css/critical.min.css")))

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [February 11, 2020, 3:10pm UTC](https://forum.litium.com/t/invalidate-cache-on-every-build-deploy-startup/1323/4 "2020-02-11T15:10:58Z")

</div>

The `FingerprintExtension.ContentFingerprint` is using the HttpContext.Cache with a file system dependency so when the file is changed the cache is removed; otherwise it using a cached fingerprint to not need to recalculate that for every request.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/12eddac3b8b661de1db86af10ac8151b571e6fb9.png) [@system](https://forum.litium.com/u/system)\
**Post date:** [March 10, 2020, 3:11pm UTC](https://forum.litium.com/t/invalidate-cache-on-every-build-deploy-startup/1323/5 "2020-03-10T15:11:00Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
