-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
代码重构:将默认的文件缓存变为数组缓存(重启后记录清空,但支持了加密数据的缓存)
- Loading branch information
1 parent
f4e730e
commit d3861c7
Showing
7 changed files
with
99 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/** | ||
* 数组缓存驱动 | ||
* User: Siam | ||
* Date: 2019/7/31 | ||
* Time: 17:56 | ||
*/ | ||
|
||
namespace Siam\HttpMonitor\Runner; | ||
|
||
use Siam\HttpMonitor\Config; | ||
use Siam\HttpMonitor\RunnerAbstract; | ||
|
||
class ArrayRunner extends RunnerAbstract | ||
{ | ||
protected $config; | ||
private $data = []; | ||
private $dataKey = []; | ||
|
||
|
||
public function __construct(Config $config) | ||
{ | ||
$this->config = $config; | ||
} | ||
|
||
public function addOne($data) | ||
{ | ||
$dataKey = time(); | ||
$this->checkSize(); | ||
|
||
$this->dataKey[] = $dataKey; | ||
$this->data[$dataKey] = $data; | ||
} | ||
|
||
public function getData($dataKey = null) | ||
{ | ||
if ($dataKey === null){ | ||
return $this->data; | ||
} | ||
if (isset($this->data[$dataKey])){ | ||
return $this->data[$dataKey]; | ||
} | ||
return null; | ||
} | ||
|
||
public function checkSize() | ||
{ | ||
if (count($this->dataKey) >= $this->config->getSize()){ | ||
$dataKey = array_pop($this->dataKey); | ||
if ($this->data[$dataKey]){ | ||
unset($this->data[$dataKey]); | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
/** | ||
* 执行者抽象 | ||
* User: Siam | ||
* Date: 2020/2/20 0020 | ||
* Time: 12:32 | ||
*/ | ||
|
||
namespace Siam\HttpMonitor; | ||
|
||
abstract class RunnerAbstract | ||
{ | ||
protected $config; | ||
|
||
abstract public function __construct(Config $config); | ||
|
||
abstract public function addOne($data); | ||
|
||
abstract public function getData($dataKey = null); | ||
|
||
abstract public function checkSize(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters