# SensorContext previousCache / nextCache

**URL:** <https://community.sonarsource.com/t/sensorcontext-previouscache-nextcache/110766>\
**Category:** Plugin Development\
**Tags:** custom\_plugin, sonarqube\
**Created:** [March 8, 2024, 4:42pm UTC](https://community.sonarsource.com/t/sensorcontext-previouscache-nextcache/110766 "2024-03-08T16:42:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gquerret](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/gquerret/32/4656_2.png) [@gquerret](https://community.sonarsource.com/u/gquerret)\
**Post date:** [March 8, 2024, 4:42pm UTC](https://community.sonarsource.com/t/sensorcontext-previouscache-nextcache/110766/1 "2024-03-08T16:42:47Z")

</div>

I’d like to speed branch analysis by using the previousCache / nextCache methods of SensorContext. The JavaDoc is quite light, so I was wondering if there was more information somewhere else.

Specifically, I’d like to know what cache I can expect when sonar-scanner is executed in a branch. If I’m on the main branch, will I get the cache from the previous analysis (usually previous commit in main) ? Same on feature branches ? First analysis will retrieve the cache of the parent commit in main branch, next analysis in feature branch will get the cache of the first commit in this branch ?

And where is the cache located ? Is that pushed to SonarQube server ? Is stored locally ? In latter case, I assume that the analysis has to be triggered on the same agent.

Thanks !  
Gilles

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [March 11, 2024, 8:38am UTC](https://community.sonarsource.com/t/sensorcontext-previouscache-nextcache/110766/2 "2024-03-11T08:38:34Z")

</div>

Hey there.

- For branch analysis, an analysis cache is stored on the server per branch.
- For pull request analysis, the cache of the base branch is used and not persisted.
- If no cache is found, the cache of the Main branch is used.

The cache is stored on the SonarQube server.

---

<div class="post-metadata">

**Author:** ![gquerret](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/gquerret/32/4656_2.png) [@gquerret](https://community.sonarsource.com/u/gquerret)\
**Post date:** [March 11, 2024, 9:28am UTC](https://community.sonarsource.com/t/sensorcontext-previouscache-nextcache/110766/3 "2024-03-11T09:28:57Z")

</div>

Thanks ! Is there a limit to the number of “caches” in the main branch ?
