forked from matomo-org/device-detector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs matomo-org#5290 - use doctrine-cache for caching
- Loading branch information
Showing
14 changed files
with
144 additions
and
420 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
/** | ||
* Device Detector - The Universal Device Detection library for parsing User Agents | ||
* | ||
* @link http://piwik.org | ||
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later | ||
*/ | ||
namespace DeviceDetector\Cache; | ||
|
||
use Doctrine\Common\Cache\CacheProvider; | ||
|
||
/** | ||
* Class StaticCache | ||
* | ||
* Simple Cache that caches in a static property | ||
* (Speeds up multiple detections in one request) | ||
* | ||
* @package DeviceDetector\Cache | ||
*/ | ||
class StaticCache extends CacheProvider | ||
{ | ||
/** | ||
* Holds the static cache data | ||
* @var array | ||
*/ | ||
static protected $staticCache = array(); | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function doFetch($id) | ||
{ | ||
return $this->doContains($id) ? self::$staticCache[$id] : false; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function doContains($id) | ||
{ | ||
return isset(self::$staticCache[$id]) || array_key_exists($id, self::$staticCache); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function doSave($id, $data, $lifeTime = 0) | ||
{ | ||
self::$staticCache[$id] = $data; | ||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function doDelete($id) | ||
{ | ||
unset(self::$staticCache[$id]); | ||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function doGetStats() | ||
{ | ||
return null; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function doFlush() | ||
{ | ||
self::$staticCache = array(); | ||
return true; | ||
} | ||
} |
Oops, something went wrong.