Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
HillLiu committed Nov 12, 2021
1 parent f5cedae commit ad01533
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
10 changes: 6 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ jobs:
parameters:
php-version:
type: string
plugin-name:
type: string
default: "minions"
docker:
- image: hillliu/pmvc-phpunit:<< parameters.php-version >>
working_directory: /var/www/minions
working_directory: /var/www/<< parameters.plugin-name >>
steps:
- checkout
- run:
Expand All @@ -34,15 +37,14 @@ jobs:
phpunit
fi
- store_artifacts:
path: /var/www/minions/clover.xml
path: /var/www/<< parameters.plugin-name >>/clover.xml
- store_artifacts:
path: /var/www/minions/coveralls-upload.json
path: /var/www/<< parameters.plugin-name >>/coveralls-upload.json

workflows:
run-job:
jobs:
- unittest:
matrix:
name: test-<< matrix.php-version >>
parameters:
php-version: ["8", "5.6"]
26 changes: 13 additions & 13 deletions src/_cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
class cache
{
private $_curl;
private $_db;
private $_storage;
public function __construct($caller)
{
$this->_curl = \PMVC\plug(minions::curl);
$this->_db = \PMVC\plug('guid')->getDb('MinionsCache');
$this->setStore(\PMVC\plug('guid')->getModel('MinionsCache'));
}

public function __invoke()
Expand Down Expand Up @@ -165,28 +165,28 @@ private function _storeCache($r, $hash, $ttl)
if ($nextBody) {
$next->body = urlencode(gzcompress($nextBody, 9));
}
$this->_db->setCache($ttl);
$this->_db[$hash] = json_encode($next);
$this->_storage->setTTL($ttl);
$this->_storage[$hash] = json_encode($next);
}

public function getCache($maybeHash)
{
$hash = $this->_getHash($maybeHash);
$r = CurlResponder::fromJson($this->_db[$hash]);
$r = CurlResponder::fromJson($this->_storage[$hash]);
if (!$r) {
return false;
}
$r->expire = $this->_db->ttl($hash);
$r->expire = $this->_storage->ttl($hash);
$r->hash = $hash;
$r->purge = $this->getPurge($hash);
$r->dbCompositeKey = $this->_db->getCompositeKey($hash);
$r->dbCompositeKey = $this->_storage->getCompositeKey($hash);
return $r;
}

public function hasCache($maybeHash)
{
$hash = $this->_getHash($maybeHash);
return isset($this->_db[$hash]);
return isset($this->_storage[$hash]);
}

public function getPurge($maybeHash)
Expand All @@ -200,9 +200,9 @@ public function getPurge($maybeHash)
public function purge($maybeHash)
{
$hash = $this->_getHash($maybeHash);
if (isset($this->_db[$hash])) {
unset($this->_db[$hash]);
return !isset($this->_db[$hash]);
if (isset($this->_storage[$hash])) {
unset($this->_storage[$hash]);
return !isset($this->_storage[$hash]);
} else {
return false;
}
Expand All @@ -223,8 +223,8 @@ public function setCurl($curl)
$this->_curl = $curl;
}

public function setStore($db)
public function setStore($model)
{
$this->_db = $db;
$this->_storage = $model;
}
}
10 changes: 5 additions & 5 deletions tests/src/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ function testCacheProcess()
_CLASS=>__NAMESPACE__.'\FakeGuid'
]);
$minions->processCache(null, 1000);
$this->assertTrue(isset($guid['db']));
$this->assertTrue(isset($guid['model']));
}
}

class FakeGuid extends PlugIn {
function getDb()
function getModel()
{
$this['db'] = new FakeMinionsDb();
return $this['db'];
$this['model'] = new FakeMinionsDb();
return $this['model'];
}
}

class FakeMinionsDb extends HashMap {
function setCache()
function setTTL()
{

}
Expand Down

0 comments on commit ad01533

Please sign in to comment.