Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better hdd cache invalidation #71

Merged
merged 2 commits into from
Feb 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions inc/cachify_hdd.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public static function delete_item($hash = '', $url)
public static function clear_cache()
{
self::_clear_dir(
CACHIFY_CACHE_DIR
CACHIFY_CACHE_DIR,
true
);
}

Expand Down Expand Up @@ -227,15 +228,16 @@ private static function _create_file($file, $data)


/**
* Clear directory recursively
* Clear directory
*
* @since 2.0
* @change 2.0.5
*
* @param string $dir Directory path
* @param string $dir Directory path
* @param boolean $recursive clear subdirectories
*/

private static function _clear_dir($dir) {
private static function _clear_dir($dir, $recursive = false) {
/* Remote training slash */
$dir = untrailingslashit($dir);

Expand All @@ -261,15 +263,17 @@ private static function _clear_dir($dir) {
$object = $dir. DIRECTORY_SEPARATOR .$object;

/* Directory or file */
if ( is_dir($object) ) {
self::_clear_dir($object);
if ( is_dir($object) && $recursive ) {
self::_clear_dir($object, $recursive);
} else {
unlink($object);
}
}

/* Remove directory */
@rmdir($dir);
if ( $recursive ) {
@rmdir($dir);
}

/* CleanUp */
clearstatcache();
Expand Down