base64Captcha icon indicating copy to clipboard operation
base64Captcha copied to clipboard

Default Memory Store

Open haseth opened this issue 4 years ago • 3 comments

in store_memory.go we have defined functionality to get and set values.

It deletes the values from the store after GCLimitNumber has reached and expiration time is over.

Issue:

  1. Captchas are present till GCLimitNumber of captchas are reached, even though captcha has expired and it will stay until garbage collected.
  2. Captchas might be retrieved again even though it might be expired.

**Proposal:** Proposal 1: While retrieving, we can check whether expired or not, if expired delete from store.

Proposal 2: We can create a wrapper structure over go-cache library.

  • Advantage: It will take care of Set, Get, and collect functionality.

haseth avatar Mar 10 '20 04:03 haseth

Hi, I would like to raise a PR w.r.t to proposal-2, I find it a better approach. Will it be a good way @slayercat @mojocn @JJJJJJJerk ?

haseth avatar Mar 16 '20 18:03 haseth

Hi, I would like to raise a PR w.r.t to proposal-2, I find it a better approach. Will it be a good way @slayercat @mojocn @JJJJJJJerk ?

how aboud just use standard library sync.Map

mojocn avatar Mar 20 '20 08:03 mojocn

We store the captcha in the memory for certain period of time expiry time and then remove it right?

So, if we use sync.Map, here is my understanding

// digits structure
type Value Struct {
val interface{}
expiration int64
}

// map of id to value
sync.map[id]value

We can do get and set for the values atomically.

But what about collection we have to write separate logic for it and might want to use locks again?

haseth avatar Mar 20 '20 11:03 haseth