]> git.wh0rd.org - tt-rss.git/commitdiff
tunables:
authorAndrew Dolgov <noreply@fakecake.org>
Mon, 29 May 2017 20:14:42 +0000 (23:14 +0300)
committerAndrew Dolgov <noreply@fakecake.org>
Mon, 29 May 2017 20:14:42 +0000 (23:14 +0300)
* add CACHE_MAX_DAYS as a tunable generic expiry interval for various cached files
* add some comments to tunables in functions.php
* rename _MIN_CACHE_FILE_SIZE to MIN_CACHE_FILE_SIZE
* respect MIN_CACHE_FILE_SIZE setting in a few more places where content is cached

classes/rssutils.php
include/functions.php
plugins/af_zz_imgproxy/init.php
plugins/cache_starred_images/init.php

index e6fe39592c00768d48f41e427056ccc128298d05..b882b872d19f92ea5dac0c6d6a62c1b82c72f31c 100644 (file)
@@ -1152,7 +1152,7 @@ class RSSUtils {
                                if (!file_exists($local_filename)) {
                                        $file_content = fetch_file_contents($src);
 
-                                       if ($file_content && strlen($file_content) > _MIN_CACHE_FILE_SIZE) {
+                                       if ($file_content && strlen($file_content) > MIN_CACHE_FILE_SIZE) {
                                                file_put_contents($local_filename, $file_content);
                                        }
                                } else {
@@ -1186,7 +1186,7 @@ class RSSUtils {
                                if (!file_exists($local_filename)) {
                                        $file_content = fetch_file_contents($src);
 
-                                       if ($file_content && strlen($file_content) > _MIN_CACHE_FILE_SIZE) {
+                                       if ($file_content && strlen($file_content) > MIN_CACHE_FILE_SIZE) {
                                                file_put_contents($local_filename, $file_content);
                                        }
                                } else {
@@ -1243,7 +1243,7 @@ class RSSUtils {
 
                                if ($files) {
                                        foreach ($files as $file) {
-                                               if (time() - filemtime($file) > 86400*7) {
+                                               if (time() - filemtime($file) > 86400*CACHE_MAX_DAYS) {
                                                        unlink($file);
 
                                                        ++$num_deleted;
index a664212b2e9d896f703a2084e0bf2085b151001d..6ea3e9ff2dea2079e53950e13ede01f5353c8321 100644 (file)
 
        /**
         * Define a constant if not already defined
-        *
-        * @param string $name The constant name.
-        * @param mixed $value The constant value.
-        * @access public
-        * @return boolean True if defined successfully or not.
         */
        function define_default($name, $value) {
                defined($name) or define($name, $value);
        }
 
-       ///// Some defaults that you can override in config.php //////
+       /* Some tunables you can override in config.php using define(): */
 
        define_default('FEED_FETCH_TIMEOUT', 45);
        // How may seconds to wait for response when requesting feed from a site
        define_default('FILE_FETCH_CONNECT_TIMEOUT', 15);
        // How many seconds to wait for initial response from website when
        // fetching files from remote sites
-
-       // feed updating stuff
        define_default('DAEMON_UPDATE_LOGIN_LIMIT', 30);
+       // stop updating feeds if users haven't logged in for X days
        define_default('DAEMON_FEED_LIMIT', 500);
+       // feed limit for one update batch
        define_default('DAEMON_SLEEP_INTERVAL', 120);
-       define_default('_MIN_CACHE_FILE_SIZE', 1024);
+       // default sleep interval between feed updates (sec)
+       define_default('MIN_CACHE_FILE_SIZE', 1024);
+       // do not cache files smaller than that (bytes)
+       define_default('CACHE_MAX_DAYS', 7);
+       // max age in days for various automatically cached (temporary) files
+
+       /* tunables end here */
 
        if (DB_TYPE == "pgsql") {
                define('SUBSTRING_FOR_DATE', 'SUBSTRING_FOR_DATE');
index 7de0c02291ab6323f5c23dfae5dede4635aac0f1..870e12a0816e9e3f3495c8c42ded95046bfd73ec 100644 (file)
@@ -69,7 +69,7 @@ class Af_Zz_ImgProxy extends Plugin {
 
                                $disable_cache = $this->host->get($this, "disable_cache");
 
-                               if (!$disable_cache) {
+                               if (!$disable_cache && strlen($data) > MIN_CACHE_FILE_SIZE) {
                                        if (file_put_contents($local_filename, $data)) {
                                                $mimetype = mime_content_type($local_filename);
                                                header("Content-type: $mimetype");
index 6c9e67b171f025c29aeea31120483a2c3a3ba4ad..527e088d584f2f75e5901d8de7bf6c68bbd6ed85 100644 (file)
@@ -209,7 +209,7 @@ class Cache_Starred_Images extends Plugin implements IHandler {
                                if (!file_exists($local_filename)) {
                                        $file_content = fetch_file_contents($src);
 
-                                       if ($file_content && strlen($file_content) > 0) {
+                                       if ($file_content && strlen($file_content) > MIN_CACHE_FILE_SIZE) {
                                                file_put_contents($local_filename, $file_content);
                                                $success = true;
                                        }