diff --git a/etc/spack/defaults/config.yaml b/etc/spack/defaults/config.yaml
index e4914e3fa32c1318f6cd93588b2277848cdea35a..28628a3d493e0f933dfc065e614cfc98f769f539 100644
--- a/etc/spack/defaults/config.yaml
+++ b/etc/spack/defaults/config.yaml
@@ -90,3 +90,7 @@ config:
   # If set to 4, for example, `spack install` will run `make -j4`.
   # If not set, all available cores are used by default.
   # build_jobs: 4
+
+
+  # If set to true, spack will use ccache to cache c compiles.
+  ccache: false
diff --git a/lib/spack/docs/config_yaml.rst b/lib/spack/docs/config_yaml.rst
index 35bc22d72e531d454454f12537d4e8ab2f690015..1db56792780a788a927bd88feb5aea307105e81c 100644
--- a/lib/spack/docs/config_yaml.rst
+++ b/lib/spack/docs/config_yaml.rst
@@ -191,3 +191,22 @@ to 4, for example, commands like ``spack install`` will run ``make -j4``
 instead of hogging every core.
 
 To build all software in serial, set ``build_jobs`` to 1.
+
+--------------------
+``ccache``
+--------------------
+
+When set to ``true`` Spack will use ccache to cache compiles. This is
+useful specifically un two cases: (1) Use with ``spack setup``, (2)
+Build the same package with many different variants. The default is
+``false``.
+
+When enabled Spack will look inside your ``PATH`` for a ``ccache``
+executable and stop if it is not found. Some systems come with
+``ccache``, but it can also be installed using ``spack install
+ccache``. ``ccache`` comes with reasonable defaults for cache size
+and location. (See the *Configuration settings* secion of ``man
+ccache`` to learn more about the default settings and how change
+them.) Please note that we currently disable ccache's ``hash_dir``
+feature to avoid an issue with the stage directory (see
+https://github.com/LLNL/spack/pull/3761#issuecomment-294352232 ).
diff --git a/lib/spack/env/cc b/lib/spack/env/cc
index 22f6cb345c3512b37061ce37544f815dabe01abf..bc4a20dc3e565dc17b133bb4fe4deadba641af03 100755
--- a/lib/spack/env/cc
+++ b/lib/spack/env/cc
@@ -342,7 +342,15 @@ case "$mode" in
         args=("${args[@]}" ${SPACK_LDLIBS[@]}) ;;
 esac
 
-full_command=("$command" "${args[@]}")
+#ccache only supports C languages, so filtering out Fortran
+if [[ ( ${lang_flags} = "C" || ${lang_flags} = "CXX" ) && ${SPACK_CCACHE_BINARY} ]]; then
+    full_command=("${SPACK_CCACHE_BINARY}" "$command" "${args[@]}")
+    # #3761#issuecomment-294352232
+    # workaround for stage being a temp folder
+    export CCACHE_NOHASHDIR=yes
+else
+   full_command=("$command" "${args[@]}")
+fi
 
 # In test command mode, write out full command for Spack tests.
 if [[ $SPACK_TEST_COMMAND == dump-args ]]; then
diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py
index 4d272b51f3f291822984b2dcb10dedd48ea15822..e48e570e76ff55f35a56291e20a35da9726ce537 100644
--- a/lib/spack/spack/build_environment.py
+++ b/lib/spack/spack/build_environment.py
@@ -98,6 +98,7 @@
 SPACK_SHORT_SPEC = 'SPACK_SHORT_SPEC'
 SPACK_DEBUG_LOG_ID = 'SPACK_DEBUG_LOG_ID'
 SPACK_DEBUG_LOG_DIR = 'SPACK_DEBUG_LOG_DIR'
+SPACK_CCACHE_BINARY = 'SPACK_CCACHE_BINARY'
 
 
 # Platform-specific library suffix.
@@ -335,6 +336,13 @@ def set_build_environment_variables(pkg, env, dirty):
     env.set(SPACK_DEBUG_LOG_ID, pkg.spec.format('${PACKAGE}-${HASH:7}'))
     env.set(SPACK_DEBUG_LOG_DIR, spack.main.spack_working_dir)
 
+    # Find ccache binary and hand it to build environment
+    if spack.config.get('config:ccache'):
+        ccache = Executable('ccache')
+        if not ccache:
+            raise RuntimeError("No ccache binary found in PATH")
+        env.set(SPACK_CCACHE_BINARY, ccache)
+
     # Add any pkgconfig directories to PKG_CONFIG_PATH
     for prefix in build_link_prefixes:
         for directory in ('lib', 'lib64', 'share'):
diff --git a/lib/spack/spack/schema/config.py b/lib/spack/spack/schema/config.py
index 4a5b25ed63a9fe4ca296d92cd6ae7ae0211b6376..ac94a12558242d233bba79cb7cc2954ebc8904d1 100644
--- a/lib/spack/spack/schema/config.py
+++ b/lib/spack/spack/schema/config.py
@@ -69,6 +69,7 @@
                 'locks': {'type': 'boolean'},
                 'dirty': {'type': 'boolean'},
                 'build_jobs': {'type': 'integer', 'minimum': 1},
+                'ccache': {'type': 'boolean'},
             }
         },
     },