# Add CACHE\_SIZE to setupVars.conf

**URL:** <https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667>\
**Category:** Implemented\
**Created:** [February 24, 2020, 10:46am UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667 "2020-02-24T10:46:01Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![PiGat](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/p/a698b9/32.png) [@PiGat](https://discourse.pi-hole.net/u/PiGat)\
**Post date:** [February 24, 2020, 10:46am UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667/1 "2020-02-24T10:46:01Z")

</div>

For the people using unbound, every update /etc/dnsmasq.d/01-pihole.conf must be changed by setting cache-size to 0. If a CACHE\_SIZE variable could be added in setupVars.conf this would make updating a whole lot easier.

---

<div class="post-metadata">

**Author:** ![jfb](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/jfb/32/4332_2.png) [@jfb](https://discourse.pi-hole.net/u/jfb)\
**Post date:** [February 24, 2020, 12:46pm UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667/2 "2020-02-24T12:46:05Z")

</div>

> [@PiGat](#):
>
> For the people using unbound, every update /etc/dnsmasq.d/01-pihole.conf must be changed by setting cache-size to 0.

Why are you disabling the cache while running unbound?

---

<div class="post-metadata">

**Author:** ![DanSchaper](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/danschaper/32/91_2.png) [@DanSchaper](https://discourse.pi-hole.net/u/DanSchaper)\
**Post date:** [February 24, 2020, 4:24pm UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667/3 "2020-02-24T16:24:34Z")

</div>

> [@PiGat](#):
>
> For the people using unbound,

We don't instruct users to disable the cache in our Unbound installation guide. [Redirecting...](https://docs.pi-hole.net/guides/unbound/)

---

<div class="post-metadata">

**Author:** ![PiGat](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/p/a698b9/32.png) [@PiGat](https://discourse.pi-hole.net/u/PiGat)\
**Post date:** [February 24, 2020, 5:26pm UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667/4 "2020-02-24T17:26:01Z")

</div>

Correct, but a double cache is pointless and all other/performance guides recommend disabling the cache in Pi-hole if used in combination with Unbound. A simple option in setupVars would solve this completely.

---

<div class="post-metadata">

**Author:** ![DanSchaper](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/danschaper/32/91_2.png) [@DanSchaper](https://discourse.pi-hole.net/u/DanSchaper)\
**Post date:** [February 24, 2020, 5:34pm UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667/5 "2020-02-24T17:34:51Z")

</div>

We don't recommend disabling the cache.

Edit: But the feature request should stay open. If others think this is useful and vote for it then it will be considered.

---

<div class="post-metadata">

**Author:** ![jfb](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/jfb/32/4332_2.png) [@jfb](https://discourse.pi-hole.net/u/jfb)\
**Post date:** [February 24, 2020, 6:02pm UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667/6 "2020-02-24T18:02:21Z")

</div>

> [@PiGat](#):
>
> all other/performance guides recommend disabling the cache in Pi-hole if used in combination with Unbound

Can you provide a few examples of these guides?

---

<div class="post-metadata">

**Author:** ![PiGat](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/p/a698b9/32.png) [@PiGat](https://discourse.pi-hole.net/u/PiGat)\
**Post date:** [February 25, 2020, 8:56am UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667/11 "2020-02-25T08:56:00Z")

</div>

[https://www.reddit.com/r/pihole/comments/d9j1z6/unbound\_as\_recursive\_dns\_server\_slow\_performance/f1jnuq1/](https://www.reddit.com/r/pihole/comments/d9j1z6/unbound_as_recursive_dns_server_slow_performance/f1jnuq1/)

[https://forum.kuketz-blog.de/viewtopic.php?t=3067](https://forum.kuketz-blog.de/viewtopic.php?t=3067)

[https://www.smarthomebeginner.com/pi-hole-setup-guide/#Combine\_Pi\_Hole\_with\_Unbound](https://www.smarthomebeginner.com/pi-hole-setup-guide/#Combine_Pi_Hole_with_Unbound)

---

<div class="post-metadata">

**Author:** ![jfb](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/jfb/32/4332_2.png) [@jfb](https://discourse.pi-hole.net/u/jfb)\
**Post date:** [February 25, 2020, 12:29pm UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667/12 "2020-02-25T12:29:58Z")

</div>

Both of those posts are in conflict with the developers recommendation for use of Pi-hole cache with unbound. Given a choice, I would follow the recommendation of the people who write the Pi-hole software.

---

<div class="post-metadata">

**Author:** ![PiGat](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/p/a698b9/32.png) [@PiGat](https://discourse.pi-hole.net/u/PiGat)\
**Post date:** [February 25, 2020, 12:36pm UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667/13 "2020-02-25T12:36:23Z")

</div>

That may be true but I needed to follow the guide on reddit because the response times were otherwise horrible. Since I've made these changes the Pi-hole + Unbound combination is very fast 🙂

---

<div class="post-metadata">

**Author:** ![PromoFaux](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/promofaux/32/1545_2.png) [@PromoFaux](https://discourse.pi-hole.net/u/PromoFaux)\
**Post date:** [February 25, 2020, 12:53pm UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667/15 "2020-02-25T12:53:18Z")

</div>

I feel that whether or not we recommend to disable the cache, there are instances where _some_ users would benefit from the ability to easily disable the cache. We don't recommend that users throw as many lists as they can possibly find, ending with blocklists sizes in the millions, but they still do it...

Personally, I don't see the harm in adding it as something like a user-configurable flag to the FTL config file. With a suitable "HERE BE DRAGONS" message in the documentation.

🤷‍♂️

---

<div class="post-metadata">

**Author:** ![sawsanders](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/s/76d3ee/32.png) [@sawsanders](https://discourse.pi-hole.net/u/sawsanders)\
**Post date:** [February 25, 2020, 1:57pm UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667/16 "2020-02-25T13:57:41Z")

</div>

I run Unbound and have tried it both ways; running with and without Pi-Hole's cache. In my situation, things are faster with cache enabled on Pi-hole.

That being said, I think it's good to have the option to change it in the GUI or CLI. If nothing else, it's easier to test.

---

<div class="post-metadata">

**Author:** ![DanSchaper](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/danschaper/32/91_2.png) [@DanSchaper](https://discourse.pi-hole.net/u/DanSchaper)\
**Post date:** [February 25, 2020, 4:32pm UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667/17 "2020-02-25T16:32:10Z")

</div>

I'll defer to DL and his knowledge of what needs to be enabled to allow our FTL features to work. And for planned features that may need it.

PR's accepted as always. Seems like a great first issue for a new contributor.

---

<div class="post-metadata">

**Author:** ![PiGat](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/p/a698b9/32.png) [@PiGat](https://discourse.pi-hole.net/u/PiGat)\
**Post date:** [February 26, 2020, 12:47pm UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667/18 "2020-02-26T12:47:25Z")

</div>

If you enable prefetch in Unbound then a local cache in pi-hole / dnsmasq prevents Unbound from knowing which records are popular and which aren't (and can then be removed from cache once full).

---

<div class="post-metadata">

**Author:** ![DanSchaper](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/danschaper/32/91_2.png) [@DanSchaper](https://discourse.pi-hole.net/u/DanSchaper)\
**Post date:** [February 26, 2020, 12:58pm UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667/19 "2020-02-26T12:58:30Z")

</div>

Interesting. My thoughts are that clients speak to Pi-hole for queries. It would seem that the fastest and highest performance would come from Pi-hole only needing to use its own internal cache to find answers to give to clients. Pi-hole having to use an external application for every query sounds like a slower option?

---

<div class="post-metadata">

**Author:** ![sawsanders](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/s/76d3ee/32.png) [@sawsanders](https://discourse.pi-hole.net/u/sawsanders)\
**Post date:** [February 26, 2020, 1:06pm UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667/20 "2020-02-26T13:06:40Z")

</div>

There’s enough cache in Unbound that I’ve never seen it fill. About 75% of Unbound’s replies come from cache in my setup probably because I have it set to serve expired.

I’ve found that the TTL on most DNS records are set low enough that Pi-Hole has to ask Unbound for an answer frequently enough that it still learns what is popular.

An answer from Pi-Hole cache is always slightly faster than one from Unbound cache in my informal testing.

---

<div class="post-metadata">

**Author:** ![PiGat](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/p/a698b9/32.png) [@PiGat](https://discourse.pi-hole.net/u/PiGat)\
**Post date:** [February 26, 2020, 1:37pm UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667/21 "2020-02-26T13:37:46Z")

</div>

That's correct, there's an additional application to go through, but Unbound can prefetch queries before they expire and thereby always serving up-to-date (ish) records. If you enable caching in dnsmasq then only a limited number of requests is sent to it and it doesn't really know what is popular and what isn't. I don't have a lot of RAM for pihole + unbound and it's running in a busy network so records need to be purged from cache regularly.

@sawsanders Yes, an answer from pihole cache is indeed faster but it's not much of an improvement. With pihole caching enabled an answer from cache is returned in 1.9ms, with Unbound as cache it's 1.95ms. This 0.05ms is easily worth the tradeoff of having a more reliable prefetch for me. Tested using namebench.

I'll see if I can get something going to add this.

---

<div class="post-metadata">

**Author:** ![mibere](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/mibere/32/18057_2.png) [@mibere](https://discourse.pi-hole.net/u/mibere)\
**Post date:** [February 26, 2020, 2:12pm UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667/22 "2020-02-26T14:12:52Z")

</div>

I don't know if this is true, but I read several times that the prefetch in Unbound only works if the requests come from multiple and different clients - which is not the case with Pi-hole (= 1 client).

In my home environment Unbounds cache hit ratio with `prefetch: yes` & `serve-expired: no` is extreme low (\<10%).

---

<div class="post-metadata">

**Author:** ![PiGat](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/p/a698b9/32.png) [@PiGat](https://discourse.pi-hole.net/u/PiGat)\
**Post date:** [February 26, 2020, 4:24pm UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667/23 "2020-02-26T16:24:34Z")

</div>

It works fine for me with one client (pihole), cache hit ratio is usually around 40% here. Nowhere in the Unbound documentation says it works any differently either. Even after a manual unbound restart it quickly picks up and prefetches stuff.

> total.num.cachehits=60  
> total.num.cachemiss=59  
> total.num.prefetch=50

---

<div class="post-metadata">

**Author:** ![DanSchaper](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/danschaper/32/91_2.png) [@DanSchaper](https://discourse.pi-hole.net/u/DanSchaper)\
**Post date:** [February 26, 2020, 5:14pm UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667/24 "2020-02-26T17:14:10Z")

</div>

> [@PiGat](#):
>
> total.num.cachehits=60  
> total.num.cachemiss=59  
> total.num.prefetch=50

Are those values in percentages or actual queries/records. 60% cache hit is significant, 60 actual cache record hits is statistically insignificant.

---

<div class="post-metadata">

**Author:** ![sawsanders](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/s/76d3ee/32.png) [@sawsanders](https://discourse.pi-hole.net/u/sawsanders)\
**Post date:** [February 26, 2020, 5:20pm UTC](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667/25 "2020-02-26T17:20:51Z")

</div>

Those numbers are actual queries. It's showing 50% cache hit.

Here's my Unbound statistics from 6 days of uptime:

```auto
total.num.queries=113770
total.num.cachehits=100633
total.num.cachemiss=13137
total.num.prefetch=83041
total.num.recursivereplies=13137

```

[Next page](https://discourse.pi-hole.net/t/add-cache-size-to-setupvars-conf/28667.md?page=2)
