Skip to content

Commit ab1d451

Browse files
committed
feat: add disable cache flag
1 parent 702ba1d commit ab1d451

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ Flags:
152152
-v --version - Get version number
153153
154154
--silent - No output and prompt
155+
--disable-cache - Disable Cache
155156
--disable-colors - Disable CLI colors
156157
157158
--limit="" - Set file mapping limit

src/Cache.php

+12
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ protected function __construct()
4040
*/
4141
public function set($key, $value, $ttl = 3600)
4242
{
43+
if (!Scanner::isCacheEnabled()) {
44+
return true;
45+
}
46+
4347
$key = $this->key($key);
4448

4549
if ($data = json_encode(array('ttl' => $ttl > 0 ? time() + $ttl : $ttl, 'data' => $value))) {
@@ -63,6 +67,10 @@ public function set($key, $value, $ttl = 3600)
6367
*/
6468
public function touch($key, $ttl = 3600)
6569
{
70+
if (!Scanner::isCacheEnabled()) {
71+
return true;
72+
}
73+
6674
if ($data = $this->get($key)) {
6775
return $this->set($key, $data, $ttl);
6876
}
@@ -80,6 +88,10 @@ public function touch($key, $ttl = 3600)
8088
*/
8189
public function get($key, $default = null)
8290
{
91+
if (!Scanner::isCacheEnabled()) {
92+
return $default;
93+
}
94+
8395
$key = $this->key($key);
8496
$file = $this->tempdir . $key;
8597

src/Console.php

+1
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ public static function helper()
560560
-v --version - Get version number
561561
562562
--silent - No output and prompt
563+
--disable-cache - Disable Cache
563564
--disable-colors - Disable CLI colors
564565
565566
--limit="" - Set file mapping limit

src/Scanner.php

+25-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ private function arguments($args = null)
350350
self::$argv->addFlag('path-quarantine', array('default' => false, 'has_value' => true));
351351
self::$argv->addFlag('path-logs', array('default' => false, 'has_value' => true));
352352
self::$argv->addFlag('path-report', array('default' => false, 'has_value' => true));
353-
self::$argv->addFlag('disable-colors', array('default' => false));
353+
self::$argv->addFlag('disable-colors', array('alias' => array('--no-colors', '--no-color'), 'default' => false));
354+
self::$argv->addFlag('disable-cache', array('alias' => '--no-cache', 'default' => false));
354355
self::$argv->addArgument('path', array('var_args' => true, 'default' => ''));
355356
self::$argv->parse($args);
356357

@@ -411,6 +412,11 @@ private function arguments($args = null)
411412
}
412413
}
413414

415+
// Cache
416+
if (isset(self::$argv['disable-cache']) && self::$argv['disable-cache']) {
417+
self::setCache(false);
418+
}
419+
414420
// Max filesize
415421
if (isset(self::$argv['max-filesize']) && is_numeric(self::$argv['max-filesize'])) {
416422
self::setMaxFilesize(self::$argv['max-filesize']);
@@ -1435,6 +1441,24 @@ public static function isColorEnabled()
14351441
return isset(self::$settings['colors']) ? self::$settings['colors'] : true;
14361442
}
14371443

1444+
/**
1445+
* @return self
1446+
*/
1447+
public static function setCache($mode = true)
1448+
{
1449+
self::$settings['cache'] = $mode;
1450+
1451+
return new static();
1452+
}
1453+
1454+
/**
1455+
* @return bool
1456+
*/
1457+
public static function isCacheEnabled()
1458+
{
1459+
return isset(self::$settings['cache']) ? self::$settings['cache'] : true;
1460+
}
1461+
14381462
/**
14391463
* @return self
14401464
*/

0 commit comments

Comments
 (0)