Skip to content

Commit

Permalink
bump 20.10.06
Browse files Browse the repository at this point in the history
- Fixed Filesystem::scanfiles() -> missing regex pattern for dump file.
- Fixed Filesystem::dump() -> retry to create a file if failed.
- Fixed WP_Object_Cache::dc_init() -> Flush Litespeed Cache admin notice if exists.
- Added Filesystem::dc_save() -> limit object size to 1000000.
- Added Garbage Collector -> action button output results.
- Added Filesystem::capture_fatal_error() -> attempt to fix any cache file error-prone.
  • Loading branch information
nawawi committed Nov 22, 2020
1 parent 1e02f69 commit ed32d6f
Show file tree
Hide file tree
Showing 14 changed files with 302 additions and 56 deletions.
9 changes: 9 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
= 20.10.06 (2020-11-23)

- Fixed Filesystem::scanfiles() -> missing regex pattern for dump file.
- Fixed Filesystem::dump() -> retry to create a file if failed.
- Fixed WP_Object_Cache::dc_init() -> Flush Litespeed Cache admin notice if exists.
- Added Filesystem::dc_save() -> limit object size to 1000000.
- Added Garbage Collector -> action button output results.
- Added Filesystem::capture_fatal_error() -> attempt to fix any cache file error-prone.

= 20.10.05 (2020-11-15)

- Fixed Litespeed Cache admin notice "Purged all caches successfully" still shown after dismiss.
Expand Down
4 changes: 2 additions & 2 deletions docket-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* @wordpress-plugin
* Plugin Name: Docket Cache
* Plugin URI: https://wordpress.org/plugins/docket-cache/
* Version: 20.10.05
* VerPrev: 20.10.04
* Version: 20.10.06
* VerPrev: 20.10.05
* Description: A persistent object cache stored as a plain PHP code, accelerates caching with OPcache backend.
* GitHub Plugin URI: https://github.com/nawawi/docket-cache
* Author: Nawawi Jamili
Expand Down
18 changes: 18 additions & 0 deletions includes/admin/docket.css
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,24 @@ body {
}

/* /eventlist */
#docket-cache .gc ul,
#docket-cache .gc li {
font-family: monospace, Consolas, Monaco;
unicode-bidi: embed;
font-weight: normal;
font-size: 11px;
margin: 0;
padding: 0;
}

#docket-cache .gc ul {
margin-left: 15px;
}

#docket-cache .gc li span {
display: inline-block;
min-width: 200px;
}

#wpfooter #footer-left,
#wpfooter #footer-upgrade {
Expand Down
31 changes: 30 additions & 1 deletion includes/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -967,13 +967,20 @@ private function dc_code($file, $arr)
}

$code = $this->fs()->code_stub($data);
$stat = $this->fs()->dump($file, $code);
$stat = $this->fs()->dump($file, $code, false); // 3rd param = validate

if (false === $stat) {
return false;
}

if (-1 === $stat) {
$this->dc_log('err', $fname, 'Failed to write');

return false;
}

$this->fs()->validate_fatal_error_file($file);

return $stat;
}

Expand Down Expand Up @@ -1046,6 +1053,14 @@ private function dc_save($cache_key, $data, $group = 'default', $expire = 0, $ke
$meta['timeout'] = $timeout;
$meta['data'] = $data;

// array size max to 1M to avoid fatal error in some hosting.
$meta_len = \count($meta, true);
if ($meta_len >= 1000000) {
$this->dc_log('err', $group.':'.$cache_key, 'Object too large: '.$meta_len.'/1000000');

return false;
}

if (true === $this->dc_code($file, $meta)) {
// if 0 let gc handle it by comparing file mtime.
if ($timeout > 0) {
Expand Down Expand Up @@ -1212,6 +1227,9 @@ function () use ($req_key) {
*/
private function dc_init()
{
// handle error
$this->fs()->capture_fatal_error();

if ($this->cf()->is_dcint('MAXSIZE', $dcvalue)) {
if ($dcvalue >= 1000000) {
$this->cache_maxsize = $dcvalue;
Expand Down Expand Up @@ -1291,6 +1309,17 @@ function () {
PHP_INT_MAX
);

add_action(
'all_admin_notices',
function () {
if (\function_exists('run_litespeed_cache')) {
$this->delete('litespeed_messages', 'options');
$this->delete('litespeed.admin_display.messages', 'options');
}
},
PHP_INT_MAX
);

foreach (['added', 'updated', 'deleted'] as $prefix) {
add_action(
$prefix.'_option',
Expand Down
2 changes: 1 addition & 1 deletion includes/object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @wordpress-plugin
* Plugin Name: Docket Cache Drop-in
* Plugin URI: https://wordpress.org/plugins/docket-cache/
* Version: 20.10.05
* Version: 20.10.06
* Description: A persistent object cache stored as a plain PHP code, accelerates caching with OPcache backend.
* Author: Nawawi Jamili
* Author URI: https://docketcache.com
Expand Down
4 changes: 2 additions & 2 deletions includes/src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function rungc()
$this->halt_error(__('Garbage collector not available.', 'docket-cache'));
}

WP_CLI::line(__('Executing garbage collector. Please wait..', 'docket-cache'));
WP_CLI::line(__('Executing the garbage collector. Please wait..', 'docket-cache'));

$pad = 35;
$collect = apply_filters('docketcache/garbage-collector', true);
Expand All @@ -228,7 +228,7 @@ public function rungc()
WP_CLI::line($this->title(__('Total Cache Ignored', 'docket-cache'), $pad).$collect->cache_ignore);
WP_CLI::line($this->title(__('Total Cache File', 'docket-cache'), $pad).$collect->cache_file);

$this->halt_success(__('Executing garbage collector completed.', 'docket-cache'));
$this->halt_success(__('Executing the garbage collector completed.', 'docket-cache'));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/src/Crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

final class Crawler
{
private static $version = '20.10.05';
private static $version = '20.10.06';
public static $send_cookie = false;

private static function default_args($param = [])
Expand Down
2 changes: 2 additions & 0 deletions includes/src/Dropino.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public function resc()
*/
public function exists()
{
clearstatcache();

return @is_file($this->resc()->dst);
}

Expand Down
29 changes: 29 additions & 0 deletions includes/src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ public function garbage_collector($force = false)
'cache_file' => 0,
'cache_cleanup' => 0,
'cache_ignore' => 0,
'cleanup_failed' => 0,
];

if ($this->pt->co()->lockproc('garbage_collector', time() + 3600)) {
Expand Down Expand Up @@ -234,13 +235,22 @@ public function garbage_collector($force = false)

if ($fm >= $ft && (0 === $fs || 'dump_' === substr($fn, 0, 5))) {
$this->pt->unlink($fx, true);

if ($force && @is_file($fx)) {
++$collect->cleanup_failed;
}

usleep(100);
continue;
}

if ($cnt >= $maxfile) {
$this->pt->unlink($fx, true);

if ($force && @is_file($fx)) {
++$collect->cleanup_failed;
}

++$collect->cleanup_maxfile;

usleep(100);
Expand All @@ -251,6 +261,10 @@ public function garbage_collector($force = false)
if ($chkmaxdisk && $fsizetotal > $maxsizedisk) {
$this->pt->unlink($fx, true);

if ($force && @is_file($fx)) {
++$collect->cleanup_failed;
}

++$collect->cleanup_maxdisk;

usleep(100);
Expand All @@ -261,6 +275,11 @@ public function garbage_collector($force = false)
if (false !== $data) {
if (!empty($data['timeout']) && $this->pt->valid_timestamp($data['timeout']) && $fm >= (int) $data['timeout']) {
$this->pt->unlink($fx, true);

if ($force && @is_file($fx)) {
++$collect->cleanup_failed;
}

unset($data);

++$collect->cleanup_maxttl;
Expand All @@ -272,6 +291,11 @@ public function garbage_collector($force = false)
if (empty($data['timeout']) && !empty($data['timestamp']) && $this->pt->valid_timestamp($data['timestamp']) && $maxttl > 0) {
if ((int) $data['timestamp'] < $maxttl) {
$this->pt->unlink($fx, true);

if ($force && @is_file($fx)) {
++$collect->cleanup_failed;
}

unset($data);
++$collect->cleanup_maxttl;

Expand All @@ -284,6 +308,11 @@ public function garbage_collector($force = false)

if ($maxttl > 0 && $ft < $maxttl) {
$this->pt->unlink($fx, true);

if ($force && @is_file($fx)) {
++$collect->cleanup_failed;
}

++$collect->cleanup_maxttl;

usleep(100);
Expand Down
Loading

0 comments on commit ed32d6f

Please sign in to comment.