1
0
mirror of https://github.com/mosbth/cimage.git synced 2025-08-04 15:17:42 +02:00

improved cache handling for remote, #130

This commit is contained in:
Mikael Roos
2015-12-07 15:12:20 +01:00
parent 3271d165ff
commit 79a7fd17d8
3 changed files with 21 additions and 24 deletions

View File

@@ -512,13 +512,15 @@ class CImage
* Allow or disallow remote image download. * Allow or disallow remote image download.
* *
* @param boolean $allow true or false to enable and disable. * @param boolean $allow true or false to enable and disable.
* @param string $cache path to cache dir.
* @param string $pattern to use to detect if its a remote file. * @param string $pattern to use to detect if its a remote file.
* *
* @return $this * @return $this
*/ */
public function setRemoteDownload($allow, $pattern = null) public function setRemoteDownload($allow, $cache, $pattern = null)
{ {
$this->allowRemote = $allow; $this->allowRemote = $allow;
$this->remoteCache = $cache;
$this->remotePattern = is_null($pattern) ? $this->remotePattern : $pattern; $this->remotePattern = is_null($pattern) ? $this->remotePattern : $pattern;
$this->log( $this->log(
@@ -650,21 +652,12 @@ class CImage
} }
$remote = new CRemoteImage(); $remote = new CRemoteImage();
$cache = $this->saveFolder . "/remote/";
if (!is_dir($cache)) { if (!is_writable($this->remoteCache)) {
if (!is_writable($this->saveFolder)) {
throw new Exception("Can not create remote cache, cachefolder not writable.");
}
mkdir($cache);
$this->log("The remote cache does not exists, creating it.");
}
if (!is_writable($cache)) {
$this->log("The remote cache is not writable."); $this->log("The remote cache is not writable.");
} }
$remote->setCache($cache); $remote->setCache($this->remoteCache);
$remote->useCache($this->useCache); $remote->useCache($this->useCache);
$src = $remote->download($src); $src = $remote->download($src);

View File

@@ -5,10 +5,11 @@ Revision history
[![Build Status](https://scrutinizer-ci.com/g/mosbth/cimage/badges/build.png?b=master)](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master) [![Build Status](https://scrutinizer-ci.com/g/mosbth/cimage/badges/build.png?b=master)](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master)
v0.7.8* (2015-12-06) v0.7.8* (2015-12-07)
------------------------------------- -------------------------------------
* Adding CCache to improve cache handling of dummy and srgb, #130. * Added correct CImage version to remote agent string, #131.
* Adding CCache to improve cache handling of caching for dummy, remote and srgb. #130.
v0.7.8 (2015-12-06) v0.7.8 (2015-12-06)

View File

@@ -348,6 +348,16 @@ $img->setVerbose($verbose || $verboseFile);
/**
* Get the cachepath from config.
*/
$cachePath = getConfig('cache_path', __DIR__ . '/../cache/');
$cache = new CCache();
$cache->setDir($cachePath);
/** /**
* Allow or disallow remote download of images from other servers. * Allow or disallow remote download of images from other servers.
* Passwords apply if used. * Passwords apply if used.
@@ -356,8 +366,10 @@ $img->setVerbose($verbose || $verboseFile);
$allowRemote = getConfig('remote_allow', false); $allowRemote = getConfig('remote_allow', false);
if ($allowRemote && $passwordMatch !== false) { if ($allowRemote && $passwordMatch !== false) {
$cacheRemote = $cache->getPathToSubdir("remote");
$pattern = getConfig('remote_pattern', null); $pattern = getConfig('remote_pattern', null);
$img->setRemoteDownload($allowRemote, $pattern); $img->setRemoteDownload($allowRemote, $pattern, $cacheRemote);
$whitelist = getConfig('remote_whitelist', null); $whitelist = getConfig('remote_whitelist', null);
$img->setRemoteHostWhitelist($whitelist); $img->setRemoteHostWhitelist($whitelist);
@@ -942,15 +954,6 @@ verbose("alias = $alias");
/**
* Get the cachepath from config.
*/
$cachePath = getConfig('cache_path', __DIR__ . '/../cache/');
$cache = new CCache();
$cache->setDir($cachePath);
/** /**
* Add cache control HTTP header. * Add cache control HTTP header.
*/ */