gin-contrib / gin-contrib/cache

Cache in InMemoryStore is broken

Open
#61 13 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
456
Forks
100
Avg merge
2h 16m
Merged PRs (30d)
2

Description

You may find the source code at https://github.com/fzlee/GoldenFly. it's a personal blog

In all, the following code demonstrates the way I use this middleware

// main.go,  init memory store
store := persistence.NewInMemoryStore(5 * time.Second)
// page/router.go, creating cached view
router.GET("/articles-sidebar/", cache.CachePage(store, time.Second * 10, PageSideBarView))

You may reproduce this issue by the following steps:

  1. goto http://ifconfiger.com
  2. open web developer tool
  3. refresh this web page for several times

there are chances we could get an invalid JSON response from the server like this:
Screen Shot 2019-12-24 at 13 15 33

seems the memory block which we used to keep response cache is modified by other requests.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the GoldenFly source at the InMemoryStore implementation and trace how CachePage reads and writes response data. Reproduce the issue by repeatedly refreshing the example page with developer tools open, then inspect concurrent requests and the cached response path. Done means repeated refreshes no longer produce invalid JSON responses.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.