Skip to content

Commit 04b07eb

Browse files
author
Ralf Grubenmann
committed
Cleanup of pyld patch
1 parent b776273 commit 04b07eb

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

renku/core/compat.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import json
2222
import os
2323
import sys
24-
from collections import deque
2524
from pathlib import Path
2625

2726
import pyld
@@ -68,19 +67,9 @@ def __exit__(self, *excinfo):
6867
FileNotFoundError = IOError
6968

7069

71-
class ActiveContextCache(object):
70+
class PatchedActiveContextCache(pyld.jsonld.ActiveContextCache):
7271
"""Pyld context cache without issue of missing contexts."""
7372

74-
def __init__(self, size=100):
75-
self.order = deque()
76-
self.cache = {}
77-
self.size = size
78-
79-
def get(self, active_ctx, local_ctx):
80-
key1 = json.dumps(active_ctx)
81-
key2 = json.dumps(local_ctx)
82-
return self.cache.get(key1, {}).get(key2)
83-
8473
def set(self, active_ctx, local_ctx, result):
8574
if len(self.order) == self.size:
8675
entry = self.order.popleft()
@@ -89,14 +78,13 @@ def set(self, active_ctx, local_ctx, result):
8978
e['localCtx'] == entry['localCtx'] for e in self.order
9079
) == 0:
9180
# only delete from cache if it doesn't exist in context deque
92-
print("this totally works")
9381
del self.cache[entry['activeCtx']][entry['localCtx']]
9482
key1 = json.dumps(active_ctx)
9583
key2 = json.dumps(local_ctx)
9684
self.order.append({'activeCtx': key1, 'localCtx': key2})
9785
self.cache.setdefault(key1, {})[key2] = json.loads(json.dumps(result))
9886

9987

100-
pyld._cache = {'activeCtx': ActiveContextCache()}
88+
pyld.jsonld._cache = {'activeCtx': PatchedActiveContextCache()}
10189

10290
__all__ = ('FileNotFoundError', 'Path', 'contextlib', 'pyld')

0 commit comments

Comments
 (0)