0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-06-15 17:18:19 +02:00

Don't apply cache factor to event cache. (#7578)

This is already correctly done when we instansiate the cache, but wasn't
when it got reloaded (which always happens at least once on startup).
This commit is contained in:
Erik Johnston 2020-05-27 12:04:37 +01:00 committed by GitHub
parent 9bac5d62b3
commit eefc6b3a0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

1
changelog.d/7578.bugfix Normal file
View file

@ -0,0 +1 @@
Fix cache config to not apply cache factor to event cache. Regression in v1.14.0rc1.

View file

@ -81,6 +81,7 @@ class LruCache(object):
"""
cache = cache_type()
self.cache = cache # Used for introspection.
self.apply_cache_factor_from_config = apply_cache_factor_from_config
# Save the original max size, and apply the default size factor.
self._original_max_size = max_size
@ -294,6 +295,9 @@ class LruCache(object):
Returns:
bool: Whether the cache changed size or not.
"""
if not self.apply_cache_factor_from_config:
return False
new_size = int(self._original_max_size * factor)
if new_size != self.max_size:
self.max_size = new_size

View file

@ -125,3 +125,19 @@ class CacheConfigTests(TestCase):
cache = LruCache(100)
add_resizable_cache("foo", cache_resize_callback=cache.set_cache_factor)
self.assertEqual(cache.max_size, 150)
def test_apply_cache_factor_from_config(self):
"""Caches can disable applying cache factor updates, mainly used by
event cache size.
"""
config = {"caches": {"event_cache_size": "10k"}}
t = TestConfig()
t.read_config(config, config_dir_path="", data_dir_path="")
cache = LruCache(
max_size=t.caches.event_cache_size, apply_cache_factor_from_config=False,
)
add_resizable_cache("event_cache", cache_resize_callback=cache.set_cache_factor)
self.assertEqual(cache.max_size, 10240)