Skip to content

Commit

Permalink
Merge pull request #71 from Syberspace/patch-1
Browse files Browse the repository at this point in the history
better hdd cache invalidation
  • Loading branch information
websupporter authored Feb 21, 2017
2 parents a3bbd93 + da1a3b0 commit 24980c0
Showing 1 changed file with 11 additions and 7 deletions.
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

0 comments on commit 24980c0

Please sign in to comment.