From 314a865ecfaa0e10609ea5e204995002100921a3 Mon Sep 17 00:00:00 2001 From: Netcarver Date: Sun, 26 Nov 2017 21:43:39 +0000 Subject: [PATCH] Start using a FileCache, rather than being one. --- BitbucketRepositoryAdaptor.php | 3 ++- CHANGELOG.md | 19 +++++++++++-------- FileCache.php | 6 +++--- GitRepositoryAdaptor.php | 16 ++++++++-------- GithubRepositoryAdaptor.php | 3 ++- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/BitbucketRepositoryAdaptor.php b/BitbucketRepositoryAdaptor.php index 1274cd1..4352a72 100644 --- a/BitbucketRepositoryAdaptor.php +++ b/BitbucketRepositoryAdaptor.php @@ -57,7 +57,8 @@ public function __construct($http, $remote, $application, array $options) { $this->debug($options['debug']); } if (array_key_exists('cache_dir', $options)) { - $this->setCacheDirectory($options['cache_dir']); + $this->cache = new \Netcarver\FileCache(); + $this->cache->setCacheDirectory($options['cache_dir']); } else { throw new \Exception('Cache directory is needed.'); } diff --git a/CHANGELOG.md b/CHANGELOG.md index 149b9b7..b36b454 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,17 @@ # **Changelog** - [Keep a Changelog] ## [Upcoming] -### Added -- Sections to the config screen - -### Changed -- Show more/Show all buttons to use current theme styles. Thanks @matjazp. - -### Removed -- Semantic versioning from changelog - not quite ready for it yet. +- Repo access code into separate adaptor classes that implement the GitRepository Interface. +- Added Github interface. +- Added basic BitBucket interface (WIP). +- Added capabilities flags to the repo interface. +- Rework the Update screen code to use the new interfaces. +- Grouped config inputs into sections on the config screen. +- Changed the Show more/Show all buttons to use current theme styles. Thanks @matjazp. +- Remove Semantic versioning from changelog - not quite ready for it yet. +- Attempt to fix "prism cannot be unloaded" issue. +- Simplifiy changelog formatting. +- Add result caching with config settings. ## [0.9.2] - 2017-11-22 diff --git a/FileCache.php b/FileCache.php index 1b7f306..c640aef 100644 --- a/FileCache.php +++ b/FileCache.php @@ -24,7 +24,7 @@ public function setCacheDirectory($dir = null) { /** * */ - protected function urlToKey($url) { + public function urlToKey($url) { $p = parse_url($url); $key = $p['host'] . str_replace('/', '-', $p['path']); return $key; @@ -51,7 +51,7 @@ protected function keyToStorageLocation($key) { /** * */ - protected function getEntryForKey($key) { + public function getEntryForKey($key) { $file = $this->keyToStorageLocation($key); $entry = @file_get_contents($file); if ($entry) { @@ -69,7 +69,7 @@ protected function getEntryForKey($key) { /** * */ - protected function setEntryForKey($key, $entry) { + public function setEntryForKey($key, $entry) { $file = $this->keyToStorageLocation($key); $entry = json_encode($entry); diff --git a/GitRepositoryAdaptor.php b/GitRepositoryAdaptor.php index 0da93d4..30b5ef7 100644 --- a/GitRepositoryAdaptor.php +++ b/GitRepositoryAdaptor.php @@ -5,9 +5,10 @@ /** * */ -class GitRepositoryAdaptor extends FileCache { +class GitRepositoryAdaptor { // Per-instance data... + protected $cache = null; protected $remote = null; protected $owner = null; protected $repo = null; @@ -52,8 +53,8 @@ protected function RepositoryRead($url, &$http_code, $json = true) { $etag = null; $last_mod = null; $headers = $this->headers; - $key = $this->urlToKey($url); - $entry = $this->getEntryForKey($key); + $key = $this->cache->urlToKey($url); + $entry = $this->cache->getEntryForKey($key); if ($entry) { $reply = $entry['reply']; $etag = $entry['etag']; @@ -95,7 +96,7 @@ protected function RepositoryRead($url, &$http_code, $json = true) { $entry['etag'] = @$response_headers['etag']; $entry['last_mod'] = @$response_headers['Last-Modified']; $entry['reply'] = $new_reply; - $this->setEntryForKey($key, $entry); + $this->cache->setEntryForKey($key, $entry); $reply = $new_reply; break; @@ -127,13 +128,12 @@ protected function RepositoryRead($url, &$http_code, $json = true) { /** * No such resource. */ - $cache_for = 2; + $cache_for = 15; $reply = null; $entry['etag'] = '404'; - $entry['last_mod'] = time() + ($cache_for * 60); // Cache 404s for 10 minutes TODO set to 600 before commit. NO COMMIT + $entry['last_mod'] = time() + ($cache_for * 60); // Cache 404s for n minutes $entry['reply'] = null; - $this->setEntryForKey($key, $entry); -\TD::barDump(sprintf("Caching returned 404 for %u minutes.", $cache_for)); + $this->cache->setEntryForKey($key, $entry); break; } diff --git a/GithubRepositoryAdaptor.php b/GithubRepositoryAdaptor.php index a4808b1..0f4d6ab 100644 --- a/GithubRepositoryAdaptor.php +++ b/GithubRepositoryAdaptor.php @@ -59,7 +59,8 @@ public function __construct($http, $remote, $application, array $options) { $this->debug($options['debug']); } if (array_key_exists('cache_dir', $options)) { - $this->setCacheDirectory($options['cache_dir']); + $this->cache = new \Netcarver\FileCache(); + $this->cache->setCacheDirectory($options['cache_dir']); } else { throw new \Exception('Cache directory is needed.'); }