2121import json
2222import os
2323import sys
24- from collections import deque
2524from pathlib import Path
2625
2726import 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