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

Commit b9ed516

Browse files
committed
added isolation for cache set/get per db name
1 parent 665dc6b commit b9ed516

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

server.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,14 @@ func ping(w http.ResponseWriter, r *http.Request) {
296296
}
297297

298298
func sudoCache(w http.ResponseWriter, r *http.Request) {
299+
conf, _, err := middleware.Extract(r, false)
300+
if err != nil {
301+
http.Error(w, err.Error(), http.StatusBadRequest)
302+
return
303+
}
304+
299305
if r.Method == http.MethodGet {
300-
key := r.URL.Query().Get("key")
306+
key := fmt.Sprintf("%s_%s", conf.Name, r.URL.Query().Get("key"))
301307
val, err := volatile.Get(key)
302308
if err != nil {
303309
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -315,6 +321,8 @@ func sudoCache(w http.ResponseWriter, r *http.Request) {
315321
return
316322
}
317323

324+
data.Key = fmt.Sprintf("%s_%s", conf.Name, data.Key)
325+
318326
if err := volatile.Set(data.Key, data.Value); err != nil {
319327
http.Error(w, err.Error(), http.StatusInternalServerError)
320328
return

0 commit comments

Comments
 (0)