# Use Gradle remote cache with DirectoryBuildCache

**URL:** <https://discuss.gradle.org/t/use-gradle-remote-cache-with-directorybuildcache/32121>\
**Category:** Help/Discuss\
**Created:** [June 17, 2019, 2:19pm UTC](https://discuss.gradle.org/t/use-gradle-remote-cache-with-directorybuildcache/32121 "2019-06-17T14:19:56Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Denis3](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@Denis3](https://discuss.gradle.org/u/Denis3)\
**Post date:** [June 17, 2019, 2:19pm UTC](https://discuss.gradle.org/t/use-gradle-remote-cache-with-directorybuildcache/32121/1 "2019-06-17T14:19:57Z")

</div>

Hi,

Does there exist a way to use remote cache with DirectoryBuildCache? I tried to use it and encouraged the following problems, DirectoryBuildCache implementation requires cache directory to be writable and puts lock on it for non CI build (with isPush disabled).

Thanks,  
Denis.

---

<div class="post-metadata">

**Author:** ![Stefan\_Wolf](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/stefan_wolf/32/5519_2.png) [@Stefan\_Wolf](https://discuss.gradle.org/u/Stefan_Wolf)\
**Post date:** [June 24, 2019, 12:52pm UTC](https://discuss.gradle.org/t/use-gradle-remote-cache-with-directorybuildcache/32121/2 "2019-06-24T12:52:25Z")

</div>

Hi,

I am not sure what you want to achieve. What does your configuration look like for configuring the remote cache?

The `DirectoryBuildCache` is meant as a local cache which is shared between build outputs on the same machine (or in the same container). If you want to share build outputs between different machines (or containers) please use an actual remote cache like the (free) [build cache node](https://hub.docker.com/r/gradle/build-cache-node/).

Cheers,  
Stefan

---

<div class="post-metadata">

**Author:** ![Denis3](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@Denis3](https://discuss.gradle.org/u/Denis3)\
**Post date:** [July 1, 2019, 11:15am UTC](https://discuss.gradle.org/t/use-gradle-remote-cache-with-directorybuildcache/32121/3 "2019-07-01T11:15:18Z")

</div>

Hi Stefan,  
I wanted to try DirectoryBuildCache as remote cache, I wasn’t able to find any information that restricts such use case, so I tried it.  
Configuration was:

val isCiServer = System.getenv().containsKey(“CI”)

buildCache {  
local {  
isEnabled = !isCiServer  
}  
remote {  
directory = File(buildCacheLocation, “build-cache”)  
isPush = isCiServer  
}  
}

Now I am using build cache node.

Thanks,  
Denis.

---

<div class="post-metadata">

**Author:** ![Stefan\_Wolf](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/stefan_wolf/32/5519_2.png) [@Stefan\_Wolf](https://discuss.gradle.org/u/Stefan_Wolf)\
**Post date:** [July 2, 2019, 7:00am UTC](https://discuss.gradle.org/t/use-gradle-remote-cache-with-directorybuildcache/32121/4 "2019-07-02T07:00:11Z")

</div>

Hi Denis,

so what you want is a read-only, shareable version of the `DirectoryBuildCache`? We don’t support this, yet, since we also track access of the entries in the cache, so it can be cleaned up. What happens if you make the file system readable? Are the locks too exclusive to allow parallel usage of the cache?

Cheers,  
Stefan

---

<div class="post-metadata">

**Author:** ![Denis3](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@Denis3](https://discuss.gradle.org/u/Denis3)\
**Post date:** [July 2, 2019, 7:50am UTC](https://discuss.gradle.org/t/use-gradle-remote-cache-with-directorybuildcache/32121/5 "2019-07-02T07:50:36Z")

</div>

Hi Stefan,

Yes, this is the use case. When file system is readonly I get the following error:

Could not create service of type BuildCacheController using BuildCacheServices.createBuildCacheController().

> Cache directory path\_to\_directory must be writable

When I provide write permissions to all the users, if first user puts lock on cache directory, the second one don’t use the cache.

Thanks,  
Denis.

---

<div class="post-metadata">

**Author:** ![Stefan\_Wolf](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/stefan_wolf/32/5519_2.png) [@Stefan\_Wolf](https://discuss.gradle.org/u/Stefan_Wolf)\
**Post date:** [July 3, 2019, 12:54pm UTC](https://discuss.gradle.org/t/use-gradle-remote-cache-with-directorybuildcache/32121/6 "2019-07-03T12:54:54Z")

</div>

We currently don’t support your use-case with the directory build cache.  
It would also great to detail your use-case better, so maybe the Gradle team can provide something out of the box for you. IIUC, you want to share a pre-populated version of a build cache between different Gradle processes on the same machine.

- how do you populate the build cache?
- what are the different Gradle processes doing on the machine?
- what is the bigger use-case you want to solve?

Cheers,  
Stefan

---

<div class="post-metadata">

**Author:** ![Denis3](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@Denis3](https://discuss.gradle.org/u/Denis3)\
**Post date:** [July 3, 2019, 1:28pm UTC](https://discuss.gradle.org/t/use-gradle-remote-cache-with-directorybuildcache/32121/7 "2019-07-03T13:28:49Z")

</div>

Hi Stefan,

The use-case is sharing pre-populated cache between different machines using shared nfs folder.  
Which is updated only by CI.  
The initial idea was to try the cache without using the server (it should be simpler at least for evaluation), because it does not work out of the box we moved to cache node.

Thanks,  
Denis.

---

<div class="post-metadata">

**Author:** ![Stefan\_Wolf](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/stefan_wolf/32/5519_2.png) [@Stefan\_Wolf](https://discuss.gradle.org/u/Stefan_Wolf)\
**Post date:** [July 3, 2019, 2:13pm UTC](https://discuss.gradle.org/t/use-gradle-remote-cache-with-directorybuildcache/32121/8 "2019-07-03T14:13:15Z")

</div>

Hi Denis,

thank you for the insights. I think we won’t be supporting sharing the cache via NFS in the mid-term. The solution to use the cache node is the best right now.

Cheers,  
Stefan
