Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit 5b02df3

Browse files
committed
Dont rewrite content identical to cached data
1 parent 6e7bed6 commit 5b02df3

File tree

1 file changed

+15
-5
lines changed
  • depends/docker-registry-core/docker_registry/core

1 file changed

+15
-5
lines changed

depends/docker-registry-core/docker_registry/core/lru.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ def wrapper(*args):
6666
key = args[-2]
6767
key = cache_key(key)
6868
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]
6974
redis_conn.set(key, content)
7075
except redis.exceptions.ConnectionError as e:
7176
logging.warning("LRU: Redis connection error: {0}".format(e))
@@ -81,11 +86,7 @@ def get(f):
8186
def wrapper(*args):
8287
key = args[-1]
8388
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)
8990

9091
if content is not None:
9192
return content
@@ -102,6 +103,15 @@ def wrapper(*args):
102103
return wrapper
103104

104105

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+
105115
def remove(f):
106116
@functools.wraps(f)
107117
def wrapper(*args):

0 commit comments

Comments
 (0)