# Caching is not working as intended

**URL:** <https://discuss.circleci.com/t/caching-is-not-working-as-intended/26921>\
**Category:** Caching Dependencies\
**Created:** [December 3, 2018, 4:34pm UTC](https://discuss.circleci.com/t/caching-is-not-working-as-intended/26921 "2018-12-03T16:34:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![breeswish](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/breeswish/32/19894_2.png) [@breeswish](https://discuss.circleci.com/u/breeswish)\
**Post date:** [December 3, 2018, 4:34pm UTC](https://discuss.circleci.com/t/caching-is-not-working-as-intended/26921/1 "2018-12-03T16:34:38Z")

</div>

Hi, my project’s integration tests met several cache-related issues, which were Ok in Circle CI 1.0 but broken recently.

1. `Environment.CIRCLE_SHA1` was unchanged

Please take a look at the step "  
Uploading ./target Cache (master branch only)" in this run: `https://circleci.com/gh/tikv/tikv/15384`.

Circle CI reported that: `Skipping cache generation, cache already exists for key: v3-target-master-aWt1SBJau3sI1Ix2iCYSsQvxk8WUCz3k1FaUSTDBdBo=-e6971e863854d5d9a91ac2ea833ddd1829388068 Found one created at 2018-11-30 11:56:12 +0000 UTC`

However the cache key is created using `Environment.CIRCLE_SHA1`, which should never be conflicted with a commit several days ago, right? Our configured cache key is: `key: v3-target-{{ .Branch }}-{{ checksum "rust-toolchain" }}-{{ .Environment.CIRCLE_SHA1 }}` (See  
[https://github.com/tikv/tikv/blob/6eb153338d1effb787a040fda4ad65b40e31d5cb/.circleci/config.yml#L128](https://github.com/tikv/tikv/blob/6eb153338d1effb787a040fda4ad65b40e31d5cb/.circleci/config.yml#L128) )

1. Cache is not reused

This build (`https://circleci.com/gh/tikv/tikv/15389`) created a cache using key `v3-target-master-aWt1SBJau3sI1Ix2iCYSsQvxk8WUCz3k1FaUSTDBdBo=-49ddf36e33400b48a5199b7041636105e3cf072e` in step “Uploading ./target Cache (master branch only)”.

3 hours later, another build (`https://circleci.com/gh/tikv/tikv/15398`) tried to use this cache in step “Downloading ./target Cache from master”, but failed:  
`No cache is found for key: v3-target-master-aWt1SBJau3sI1Ix2iCYSsQvxk8WUCz3k1FaUSTDBdBo=`. This is a perfect prefix match.

Notice that, as described above, the key format is `v3-target-{{ .Branch }}-{{ checksum "rust-toolchain" }}-{{ .Environment.CIRCLE_SHA1 }}`, and we have not changed the content of “rust-toolchain” for several months. So simply speaking, on master branches builds always upload cache named `v3-target-master-xxx-yyy` where `yyy` should be changed each time and `xxx` has not been changed for very long time. Then PR builds always load cache using prefix `v3-target-master-xxx`. As you can see however, the cache loading was not succeeded. This situation has been happening for long time (several weeks), which causes our test time from 20 minutes to 1 hours each.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [March 3, 2019, 4:43pm UTC](https://discuss.circleci.com/t/caching-is-not-working-as-intended/26921/2 "2019-03-03T16:43:31Z")

</div>

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