This repository was archived by the owner on Sep 12, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed
depends/docker-registry-core/docker_registry/core Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,11 @@ def wrapper(*args):
66
66
key = args [- 2 ]
67
67
key = cache_key (key )
68
68
try :
69
+ cached_content = get_by_key (key )
70
+ if cached_content and cached_content == content :
71
+ # If cached content is the same as what we are about to
72
+ # write, we don't need to write again.
73
+ return args [- 2 ]
69
74
redis_conn .set (key , content )
70
75
except redis .exceptions .ConnectionError as e :
71
76
logging .warning ("LRU: Redis connection error: {0}" .format (e ))
@@ -81,11 +86,7 @@ def get(f):
81
86
def wrapper (* args ):
82
87
key = args [- 1 ]
83
88
key = cache_key (key )
84
- try :
85
- content = redis_conn .get (key )
86
- except redis .exceptions .ConnectionError as e :
87
- logging .warning ("LRU: Redis connection error: {0}" .format (e ))
88
- content = None
89
+ content = get_by_key (key )
89
90
90
91
if content is not None :
91
92
return content
@@ -102,6 +103,15 @@ def wrapper(*args):
102
103
return wrapper
103
104
104
105
106
+ def get_by_key (key ):
107
+ try :
108
+ content = redis_conn .get (key )
109
+ except redis .exceptions .ConnectionError as e :
110
+ logging .warning ("LRU: Redis connection error: {0}" .format (e ))
111
+ return None
112
+ return content
113
+
114
+
105
115
def remove (f ):
106
116
@functools .wraps (f )
107
117
def wrapper (* args ):
You can’t perform that action at this time.
0 commit comments