Can I have the Cache and eat it too?

A cool addition to BranchCache in Windows 10 is auto shrinking of the BranchCache data cache if required. It addresses a common issue when deploying BranchCache – that of Cache size. Previously you could assign the BranchCache Cache as a percentage of disk, or as an absolute value in Mb. But what happens when the user fills up the drive? In Windows 10 Windows will now automatically shrink the cache, but how does that work?

If the client drive fills up, the actual data in the cache will be deleted and new data will overwrite the left data in the cache, that part is pretty clear and obvious. But what if the user removed data on the drive, will ever the maximum size be reused? Or is the dynamic shrink a reduction of the limit? If that is the case, you have to increase the limit manually again?

Well here is the answer, straight from the mouth of the BranchCache developers:

BC size reduction kicks in only upon low disk condition. It is an additional percentage scale factor applied to the configured limit when the machine is in low disk space.

If your BranchCache disk usage is configured to, let’s say, 5%, the actual limit used is something like: K * 5%, with 0 <= K <= 1. With a few approximations K is as follows:

• K = 1, if current % free disk space >= 10% total disk space
• K = 0, if current % free disk space <= 2% total disk space
• K = (current_percent_free_space – 2) / (10 – 2), if 2% total disk space < current % free disk space < 10% total disk space

Those limits are applied lazily, the disk space converges to the current K * 5% in time, so if disk space decreases fast enough, the user can still experience out-of-disk conditions before BranchCache has a chance to shrink its cache. Even when K=0, the cache size never actually goes down to zero, as the underlying database keeps around a minimal metadata amount (I believe it is around 50-to-100 MBs).

If K<1 and the user frees space on the disk (deleting BranchCache unrelated that somewhere else), that K * 5% goes back to 1 * 5% and the cache is allowed to grow back to that size.

If the user manually removes cache data in a “legal way” (such as “netsh branchcache flush” or “powershell Clear-BCCache”), the cache will be filled again to the limit.

If the user manually removes cache data in a “illegal way” (e.g. deleting files on the disk manually), bets are off, BranchCache may or may not figure out that those files are gone until the next cache “powershell Clear-BCCache”.

How awesome is that? Pretty shiny I would say! 🙂

TL;DR; Set a large BranchCache size and sit back and relax.