diff --git a/config/application.config.php b/config/application.config.php
index 10383a89dffda137adc2c53c5ad46bbf7c0bda00..357a2e6f6536fd7c16f1413dcd160aef857477d4 100644
--- a/config/application.config.php
+++ b/config/application.config.php
@@ -19,7 +19,8 @@ if ($localModules = getenv('VUFIND_LOCAL_MODULES')) {
     }
 }
 
-// Set up cache directory (be sure to keep separate cache for CLI vs. web):
+// Set up cache directory (be sure to keep separate cache for CLI vs. web and
+// to account for potentially variant environment settings):
 $baseDir = ($local = getenv('VUFIND_LOCAL_DIR')) ? $local : 'data';
 if (PHP_SAPI == 'cli') {
     $cacheDir = $baseDir . '/cache/cli';
@@ -33,6 +34,15 @@ if (PHP_SAPI == 'cli') {
 if (!is_dir($cacheDir)) {
     mkdir($cacheDir);
 }
+$cacheHash = md5(
+    APPLICATION_ENV
+    . (defined('VUFIND_LOCAL_DIR') ? VUFIND_LOCAL_DIR : '')
+    . implode(',', $modules)
+);
+$cacheDir .= '/' . $cacheHash;
+if (!is_dir($cacheDir)) {
+    mkdir($cacheDir);
+}
 
 // Enable caching unless in dev mode or running tests:
 $useCache = APPLICATION_ENV != 'development' && !defined('VUFIND_PHPUNIT_RUNNING');