# Caching composer dependencies

**URL:** <https://discuss.circleci.com/t/caching-composer-dependencies/1215>\
**Category:** Build Environment\
**Tags:** composer, php, caching, how-to\
**Created:** [December 18, 2015, 7:19pm UTC](https://discuss.circleci.com/t/caching-composer-dependencies/1215 "2015-12-18T19:19:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![frank](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/frank/32/124_2.png) [@frank](https://discuss.circleci.com/u/frank)\
**Post date:** [December 18, 2015, 7:19pm UTC](https://discuss.circleci.com/t/caching-composer-dependencies/1215/1 "2015-12-18T19:19:12Z")

</div>

**TL;DR** Add this to your circle.yml:

```auto
dependencies:
  cache_directories:
    - ~/.composer/cache

```

* * *

A naive way to cache composer dependencies would be to add the install directory to the [`cache_directories`](https://circleci.com/docs/how-cache-works/) section of your circle.yml. Unfortunately, composer doesn’t seem to care that you have cached dependencies and will install them all over again. You can fix this by adding composer’s cache to your `cache_directories`. This way, composer does not need to download your dependencies on every build.

---

<div class="post-metadata">

**Author:** ![mikeschinkel](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/mikeschinkel/32/16453_2.png) [@mikeschinkel](https://discuss.circleci.com/u/mikeschinkel)\
**Post date:** [July 25, 2017, 4:58am UTC](https://discuss.circleci.com/t/caching-composer-dependencies/1215/2 "2017-07-25T04:58:59Z")

</div>

This was **super** helpful, thanks. But incomplete.

To really speed up Composer you also need to cache the `vendor` directory. And it only took me a few extra hours to finally figure that out… ☹

---

<div class="post-metadata">

**Author:** ![liaogz82](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/liaogz82/32/11604_2.png) [@liaogz82](https://discuss.circleci.com/u/liaogz82)\
**Post date:** [April 1, 2018, 12:31am UTC](https://discuss.circleci.com/t/caching-composer-dependencies/1215/3 "2018-04-01T00:31:31Z")

</div>

Hi. do I need to use `restore_cache` and `save_cache` on top of `cache_directories`??

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [April 1, 2018, 12:51pm UTC](https://discuss.circleci.com/t/caching-composer-dependencies/1215/4 "2018-04-01T12:51:19Z")

</div>

@liaogz82: what are you trying to do? I am not sure if your question is answerable without a lot more context.

---

<div class="post-metadata">

**Author:** ![frank](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/frank/32/124_2.png) [@frank](https://discuss.circleci.com/u/frank)\
**Post date:** [June 30, 2018, 12:59pm UTC](https://discuss.circleci.com/t/caching-composer-dependencies/1215/5 "2018-06-30T12:59:06Z")

</div>

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