Skip to content

Commit

Permalink
Merge pull request #39 from chillu/pulls/cachedir
Browse files Browse the repository at this point in the history
Allow cacheDir config
  • Loading branch information
Damian Mooyman committed Jan 14, 2016
2 parents 9861bf5 + 40a7a4f commit f44e6a5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ See [dynamiccache.yml](_config/dynamiccache.yml) for the list of configurable op
content for different hostname, but still uses the same backend, such as the
subsites module
* enableAjax - (boolean) Determine if caching should be enabled during ajax
* cacheDir - (string) Directory where file-based caches are stored
(either absolute, or relative to TEMP_FOLDER).
Allows usage of %BASE_PATH% and %ASSETS_PATH% placeholders.
Please ensure that the folder is either located outside of the webroot, or appropriately secured.
* cacheDuration - (null|integer) Duration of the page cache, in seconds (default is 1 hour).
* cacheHeaders - (null|string) Determines which headers should also be cached.
X-Include-CSS and other relevant headers can be essential in instructing the
Expand Down
4 changes: 4 additions & 0 deletions _config/dynamiccache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ DynamicCache:
segmentHostname: true
# Determine if caching should be enabled during ajax
enableAjax: false
# Directory where file-based caches are stored (either absolute, or relative to TEMP_FOLDER)
# Allows usage of %BASE_PATH% and %ASSETS_PATH% placeholders.
# Please ensure that the folder is either located outside of the webroot, or appropriately secured.
cacheDir: 'dynamic_cache'
# Duration of the page cache, in seconds
cacheDuration: 3600
# Determines which headers should also be cached. X-Include-CSS and other relevant
Expand Down
18 changes: 17 additions & 1 deletion code/DynamicCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,24 @@ protected function getCache()
// Create default backend if not overridden
if ($backend === 'DynamicCache') {

$cacheDir = str_replace(
array(
'%BASE_PATH%',
'%ASSETS_PATH%'
),
array(
BASE_PATH,
ASSETS_PATH
),
self::config()->cacheDir
);

// Using own folder helps with separating page cache from other SS cached elements
$cacheDir = TEMP_FOLDER . DIRECTORY_SEPARATOR . 'dynamic_cache';
// TODO Use Filesystem::isAbsolute() once $_ENV['OS'] bug is fixed (should use getenv())
if ($cacheDir[0] !== '/') {
$cacheDir = TEMP_FOLDER . DIRECTORY_SEPARATOR . $cacheDir;
}

if (!is_dir($cacheDir)) {
mkdir($cacheDir);
}
Expand Down

0 comments on commit f44e6a5

Please sign in to comment.