Bläddra i källkod

Option to force clear cache (#2052)

https://github.com/FreshRSS/FreshRSS/issues/1020#issuecomment-428515868
Alexandre Alapetite 7 år sedan
förälder
incheckning
0aecf44294

+ 1 - 0
app/Controllers/subscriptionController.php

@@ -98,6 +98,7 @@ class FreshRSS_subscription_Controller extends Minz_ActionController {
 
 			$feed->_attributes('mark_updated_article_unread', Minz_Request::paramTernary('mark_updated_article_unread'));
 			$feed->_attributes('read_upon_reception', Minz_Request::paramTernary('read_upon_reception'));
+			$feed->_attributes('clear_cache', Minz_Request::paramTernary('clear_cache'));
 
 			if (FreshRSS_Auth::hasAccess('admin')) {
 				$feed->_attributes('ssl_verify', Minz_Request::paramTernary('ssl_verify'));

+ 13 - 1
app/Models/Feed.php

@@ -286,6 +286,10 @@ class FreshRSS_Feed extends Minz_Model {
 				if (!$loadDetails) {	//Only activates auto-discovery when adding a new feed
 					$feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE);
 				}
+				if ($this->attributes('clear_cache')) {
+					// Do not use `$simplePie->enable_cache(false);` as it would prevent caching in multiuser context
+					$this->clearCache();
+				}
 				Minz_ExtensionManager::callHook('simplepie_before_init', $feed, $this);
 				$mtime = $feed->init();
 
@@ -465,8 +469,16 @@ class FreshRSS_Feed extends Minz_Model {
 		$this->entries = $entries;
 	}
 
+	protected function cacheFilename() {
+		return CACHE_PATH . '/' . md5($this->url) . '.spc';
+	}
+
+	public function clearCache() {
+		return @unlink($this->cacheFilename());
+	}
+
 	public function cacheModifiedTime() {
-		return @filemtime(CACHE_PATH . '/' . md5($this->url) . '.spc');
+		return @filemtime($this->cacheFilename());
 	}
 
 	public function lock() {

+ 1 - 0
app/i18n/cz/sub.php

@@ -27,6 +27,7 @@ return array(
 			'password' => 'Heslo',
 			'username' => 'Přihlašovací jméno',
 		),
+		'clear_cache' => 'Always clear cache',	//TODO
 		'css_help' => 'Stáhne zkrácenou verzi RSS kanálů (pozor, náročnější na čas!)',
 		'css_path' => 'Původní CSS soubor článku z webových stránek',
 		'description' => 'Popis',

+ 1 - 0
app/i18n/de/sub.php

@@ -27,6 +27,7 @@ return array(
 			'password' => 'HTTP-Passwort',
 			'username' => 'HTTP-Nutzername',
 		),
+		'clear_cache' => 'Always clear cache',	//TODO
 		'css_help' => 'Ruft gekürzte RSS-Feeds ab (Achtung, benötigt mehr Zeit!)',
 		'css_path' => 'Pfad zur CSS-Datei des Artikels auf der Original-Webseite',
 		'description' => 'Beschreibung',

+ 1 - 0
app/i18n/en/sub.php

@@ -27,6 +27,7 @@ return array(
 			'password' => 'HTTP password',
 			'username' => 'HTTP username',
 		),
+		'clear_cache' => 'Always clear cache',
 		'css_help' => 'Retrieves truncated RSS feeds (caution, requires more time!)',
 		'css_path' => 'Articles CSS path on original website',
 		'description' => 'Description',

+ 1 - 0
app/i18n/es/sub.php

@@ -22,6 +22,7 @@ return array(
 			'password' => 'Contraseña HTTP',
 			'username' => 'Nombre de usuario HTTP',
 		),
+		'clear_cache' => 'Always clear cache',	//TODO
 		'css_help' => 'Recibir fuentes RSS truncadas (aviso, ¡necesita más tiempo!)',
 		'css_path' => 'Ruta a la CSS de los artículos en la web original',
 		'description' => 'Descripción',

+ 1 - 0
app/i18n/fr/sub.php

@@ -27,6 +27,7 @@ return array(
 			'password' => 'Mot de passe HTTP',
 			'username' => 'Identifiant HTTP',
 		),
+		'clear_cache' => 'Toujours vider le cache',
 		'css_help' => 'Permet de récupérer les flux tronqués (attention, demande plus de temps !)',
 		'css_path' => 'Sélecteur CSS des articles sur le site d’origine',
 		'description' => 'Description',

+ 1 - 0
app/i18n/he/sub.php

@@ -27,6 +27,7 @@ return array(
 			'password' => 'HTTP סיסמה',
 			'username' => 'HTTP שם משתמש',
 		),
+		'clear_cache' => 'Always clear cache',	//TODO
 		'css_help' => 'קבלת הזנות RSS קטומות  (זהירות, לוקח זמן רב יותר!)',
 		'css_path' => 'נתיב הCSS של המאמר באתר המקורי',
 		'description' => 'תיאור',

+ 1 - 0
app/i18n/it/sub.php

@@ -27,6 +27,7 @@ return array(
 			'password' => 'HTTP password',
 			'username' => 'HTTP username',
 		),
+		'clear_cache' => 'Always clear cache',	//TODO
 		'css_help' => 'In caso di RSS feeds troncati (attenzione, richiede molto tempo!)',
 		'css_path' => 'Percorso del foglio di stile CSS del sito di origine',
 		'description' => 'Descrizione',

+ 1 - 0
app/i18n/kr/sub.php

@@ -27,6 +27,7 @@ return array(
 			'password' => 'HTTP 암호',
 			'username' => 'HTTP 사용자 이름',
 		),
+		'clear_cache' => 'Always clear cache',	//TODO
 		'css_help' => '글의 일부가 포함된 RSS 피드를 가져옵니다 (주의, 시간이 좀 더 걸립니다!)',
 		'css_path' => '웹사이트 상의 글 본문에 해당하는 CSS 경로',
 		'description' => '설명',

+ 1 - 0
app/i18n/nl/sub.php

@@ -27,6 +27,7 @@ return array(
 			'password' => 'HTTP wachtwoord',
 			'username' => 'HTTP gebruikers naam',
 		),
+		'clear_cache' => 'Always clear cache',	//TODO
 		'css_help' => 'Haalt verstoorde RSS feeds op (attentie, heeft meer tijd nodig!)',
 		'css_path' => 'Artikelen CSS pad op originele website',
 		'description' => 'Omschrijving',

+ 1 - 0
app/i18n/pt-br/sub.php

@@ -27,6 +27,7 @@ return array(
 			'password' => 'Senha HTTP',
 			'username' => 'Usuário HTTP',
 		),
+		'clear_cache' => 'Always clear cache',	//TODO
 		'css_help' => 'Retorna RSS feeds truncados (atenção, requer mais tempo!)',
 		'css_path' => 'Caminho do CSS do artigo no site original',
 		'description' => 'Descrição',

+ 1 - 0
app/i18n/ru/sub.php

@@ -27,6 +27,7 @@ return array(
 			'password' => 'HTTP password',// TODO
 			'username' => 'HTTP username',// TODO
 		),
+		'clear_cache' => 'Always clear cache',	//TODO
 		'css_help' => 'Retrieves truncated RSS feeds (caution, requires more time!)',// TODO
 		'css_path' => 'Articles CSS path on original website',// TODO
 		'description' => 'Description',// TODO

+ 1 - 0
app/i18n/tr/sub.php

@@ -27,6 +27,7 @@ return array(
 			'password' => 'HTTP şifre',
 			'username' => 'HTTP kullanıcı adı',
 		),
+		'clear_cache' => 'Always clear cache',	//TODO
 		'css_help' => 'Dikkat, daha çok zaman gerekir!',
 		'css_path' => 'Makaleleri kendi CSS görünümü ile göster',
 		'description' => 'Tanım',

+ 1 - 0
app/i18n/zh-cn/sub.php

@@ -27,6 +27,7 @@ return array(
 			'password' => 'HTTP 密码',
 			'username' => 'HTTP 用户名',
 		),
+		'clear_cache' => 'Always clear cache',	//TODO
 		'css_help' => '用于获取全文(注意,这将耗费更多时间!)',
 		'css_path' => '原文的 CSS 选择器',
 		'description' => '描述',

+ 7 - 0
app/views/helpers/feed/update.phtml

@@ -205,6 +205,13 @@
 			</div>
 		</div>
 
+		<div class="form-group">
+			<label class="group-name" for="clear_cache"><?php echo _t('sub.feed.clear_cache'); ?></label>
+			<div class="group-controls">
+				<input type="checkbox" name="clear_cache" id="clear_cache" value="1"<?php echo $this->feed->attributes('clear_cache') ? ' checked="checked"' : ''; ?> />
+			</div>
+		</div>
+
 		<?php if (FreshRSS_Auth::hasAccess('admin')) { ?>
 		<div class="form-group">
 			<label class="group-name" for="timeout"><?php echo _t('sub.feed.timeout'); ?></label>