Skip to content

Commit c6f1ede

Browse files
authored
Add session_registry doctest (#523)
* Add session_registry doctest Signed-off-by: Mihai Criveti <[email protected]> * Revert session_registry Signed-off-by: Mihai Criveti <[email protected]> * Update session_registry docstring Signed-off-by: Mihai Criveti <[email protected]> * Ignore DAR402 darlint flake8 plugin Signed-off-by: Mihai Criveti <[email protected]> * Ignore DAR402 darlint flake8 plugin Signed-off-by: Mihai Criveti <[email protected]> --------- Signed-off-by: Mihai Criveti <[email protected]>
1 parent f0175b7 commit c6f1ede

File tree

3 files changed

+453
-106
lines changed

3 files changed

+453
-106
lines changed

.darglint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[darglint]
2-
docstring_style=google
2+
ignore=DAR402

mcpgateway/cache/resource_cache.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,21 @@ def get(self, key: str) -> Optional[Any]:
120120
Returns:
121121
Cached value or None if not found/expired
122122
123-
Doctest:
124-
>>> from mcpgateway.cache.resource_cache import ResourceCache
125-
>>> cache = ResourceCache(max_size=2, ttl=1)
126-
>>> cache.set('a', 1)
127-
>>> cache.get('a')
128-
1
129-
>>> import time
130-
>>> time.sleep(1.1)
131-
>>> cache.get('a') is None
132-
True
123+
Example:
124+
>>> from mcpgateway.cache.resource_cache import ResourceCache
125+
>>> cache = ResourceCache(max_size=2, ttl=1)
126+
>>> cache.set('a', 1)
127+
>>> cache.get('a')
128+
1
129+
>>> # Test expiration by using a very short TTL
130+
>>> short_cache = ResourceCache(max_size=2, ttl=0.1)
131+
>>> short_cache.set('b', 2)
132+
>>> short_cache.get('b')
133+
2
134+
>>> import time
135+
>>> time.sleep(1)
136+
>>> short_cache.get('b') is None
137+
True
133138
"""
134139
if key not in self._cache:
135140
return None

0 commit comments

Comments
 (0)