|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
| 15 | +import logging |
15 | 16 | import os |
16 | 17 | import re |
17 | 18 | import threading |
|
23 | 24 |
|
24 | 25 | from ._base import Config, ConfigError |
25 | 26 |
|
| 27 | +logger = logging.getLogger(__name__) |
| 28 | + |
26 | 29 | # The prefix for all cache factor-related environment variables |
27 | 30 | _CACHE_PREFIX = "SYNAPSE_CACHE_FACTOR" |
28 | 31 |
|
@@ -148,11 +151,16 @@ def generate_config_section(self, **kwargs) -> str: |
148 | 151 | per_cache_factors: |
149 | 152 | #get_users_who_share_room_with_user: 2.0 |
150 | 153 |
|
151 | | - # Controls how long an entry can be in a cache without having been |
152 | | - # accessed before being evicted. Defaults to None, which means |
153 | | - # entries are never evicted based on time. |
| 154 | + # Controls whether cache entries are evicted after a specified time |
| 155 | + # period. Defaults to true. Uncomment to disable this feature. |
| 156 | + # |
| 157 | + #expire_caches: false |
| 158 | +
|
| 159 | + # If expire_caches is enabled, this flag controls how long an entry can |
| 160 | + # be in a cache without having been accessed before being evicted. |
| 161 | + # Defaults to 30m. Uncomment to set a different time to live for cache entries. |
154 | 162 | # |
155 | | - #expiry_time: 30m |
| 163 | + #cache_entry_ttl: 30m |
156 | 164 |
|
157 | 165 | # Controls how long the results of a /sync request are cached for after |
158 | 166 | # a successful response is returned. A higher duration can help clients with |
@@ -217,12 +225,30 @@ def read_config(self, config, **kwargs) -> None: |
217 | 225 | e.message # noqa: B306, DependencyException.message is a property |
218 | 226 | ) |
219 | 227 |
|
220 | | - expiry_time = cache_config.get("expiry_time") |
221 | | - if expiry_time: |
222 | | - self.expiry_time_msec: Optional[int] = self.parse_duration(expiry_time) |
| 228 | + expire_caches = cache_config.get("expire_caches", True) |
| 229 | + cache_entry_ttl = cache_config.get("cache_entry_ttl", "30m") |
| 230 | + |
| 231 | + if expire_caches: |
| 232 | + self.expiry_time_msec: Optional[int] = self.parse_duration(cache_entry_ttl) |
223 | 233 | else: |
224 | 234 | self.expiry_time_msec = None |
225 | 235 |
|
| 236 | + # Backwards compatibility support for the now-removed "expiry_time" config flag. |
| 237 | + expiry_time = cache_config.get("expiry_time") |
| 238 | + |
| 239 | + if expiry_time and expire_caches: |
| 240 | + logger.warning( |
| 241 | + "You have set two incompatible options, expiry_time and expire_caches. Please only use the " |
| 242 | + "expire_caches and cache_entry_ttl options and delete the expiry_time option as it is " |
| 243 | + "deprecated." |
| 244 | + ) |
| 245 | + if expiry_time: |
| 246 | + logger.warning( |
| 247 | + "Expiry_time is a deprecated option, please use the expire_caches and cache_entry_ttl options " |
| 248 | + "instead." |
| 249 | + ) |
| 250 | + self.expiry_time_msec = self.parse_duration(expiry_time) |
| 251 | + |
226 | 252 | self.sync_response_cache_duration = self.parse_duration( |
227 | 253 | cache_config.get("sync_response_cache_duration", 0) |
228 | 254 | ) |
|
0 commit comments