Support » Plugin: Redis Object Cache » Why doesn’t set a MaxTTL by default?

  • Resolved erikdemarco


    Cache is supposed to be temporary storage, not a server crasher.
    If all unknown people just install this without modifying the maxttl, they just need to wait before the memory gets full and gets OOM error.

    Why not helps them? If you dont know how. At very least let them know its very important to change maxttl.

    As a developer its very very very very very very 100x easy for you to set default maxttl. Let me tell you how:

    just modify this line in your object-cache.php:

    wp_cache_add( $key, $value, $group = '', $expiration = 0 )
    wp_cache_replace( $key, $value, $group = '', $expiration = 0 )
    wp_cache_set( $key, $value, $group = '', $expiration = 0 )

    You can modify like for example to this:

    wp_cache_add( $key, $data, $group = '', $expiration = WP_REDIS_DEFAULT_MAXTTL )
    wp_cache_replace( $key, $data, $group = '', $expiration = WP_REDIS_DEFAULT_MAXTTL )
    wp_cache_set( $key, $data, $group = '', $expiration = WP_REDIS_DEFAULT_MAXTTL )

    Then you can set ‘WP_REDIS_DEFAULT_MAXTTL’ anywhere on your plugin directory, for example on very top of your ‘object-cache.php’, you dont need wp-config.php to change that ‘WP_REDIS_DEFAULT_MAXTTL’ const.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Yui



    The plugin actually consists of 2 parts,

    the caching is done by drop-in (object-cache.php) which does work stand alone of the “main” plugin and therefore does not inherits its code and DB stored settings.

    It can be tuned only via wp-config.php variables or defines.
    Setting MaxTTL from the plugin settings will require it to edit wp-config.php

    PS: regarding OOM,
    make sure you have configured your redis-server properly.

    maxmemory 256Mb
    maxmemory-policy volatile-ttl


    maxmemory-policy allkeys-lru

    • This reply was modified 1 month ago by Yui.
    Plugin Author Till Krüss


    This plugin doesn’t set a default expiration time, because every WordPress is so drastically different when it comes to object cache usage and consumption.

    Setting a default value too low would still cause OOM errors, setting it too high would cause the cache being very inefficient.

    Some users only consume 10MB of Redis space and cache everything forever, others are driving 10Gbps of Redis traffic (every second).

    However you don’t have to modify the object cache dropin to set an expiration. The plugin comes with a WP_REDIS_MAXTTL to set:

    In addition to what Yui said: A Redis eviction policy is very important to set BUT it can be relatively slow and CPU consuming. You ideally want to run at around 60% Redis memory and find the ideal MAXTTL value.

    Or of course have a massive Redis instance so you won’t ever run out of memory.

    Does that answer all your questions, or can I help in any other way?

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.