summary refs log tree commit diff
path: root/synapse/util
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-03-22 18:22:52 +0000
committerErik Johnston <erik@matrix.org>2016-03-23 14:53:53 +0000
commit75daede92f041500347a5f446229be5ca50c2b8e (patch)
treefe29a801a1f5fdbe12424846f1c2052135c49fad /synapse/util
parentMerge pull request #664 from matrix-org/erikj/public_room_list (diff)
downloadsynapse-75daede92f041500347a5f446229be5ca50c2b8e.tar.xz
String intern
Diffstat (limited to 'synapse/util')
-rw-r--r--synapse/util/caches/__init__.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/synapse/util/caches/__init__.py b/synapse/util/caches/__init__.py
index 1a14904194..9d450fade5 100644
--- a/synapse/util/caches/__init__.py
+++ b/synapse/util/caches/__init__.py
@@ -14,6 +14,7 @@
 # limitations under the License.
 
 import synapse.metrics
+from lrucache import LruCache
 
 DEBUG_CACHES = False
 
@@ -25,3 +26,10 @@ cache_counter = metrics.register_cache(
     lambda: {(name,): len(caches_by_name[name]) for name in caches_by_name.keys()},
     labels=["name"],
 )
+
+_string_cache = LruCache(5000)
+caches_by_name["string_cache"] = _string_cache
+
+
+def intern_string(string):
+    return _string_cache.setdefault(string, string)