Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Measure metrics of string_cache #1821

Merged
merged 1 commit into from Jan 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions synapse/util/caches/__init__.py
Expand Up @@ -40,8 +40,8 @@ def register_cache(name, cache):
)


_string_cache = LruCache(int(5000 * CACHE_SIZE_FACTOR))
caches_by_name["string_cache"] = _string_cache
_string_cache = LruCache(int(100000 * CACHE_SIZE_FACTOR))
_stirng_cache_metrics = register_cache("string_cache", _string_cache)


KNOWN_KEYS = {
Expand Down Expand Up @@ -69,7 +69,12 @@ def register_cache(name, cache):
def intern_string(string):
"""Takes a (potentially) unicode string and interns using custom cache
"""
return _string_cache.setdefault(string, string)
new_str = _string_cache.setdefault(string, string)
if new_str is string:
_stirng_cache_metrics.inc_hits()
else:
_stirng_cache_metrics.inc_misses()
return new_str


def intern_dict(dictionary):
Expand Down