phuslu / lru

High performance LRU cache
MIT License
189 stars 7 forks source link

Please add the feature: sliding caching #1

Closed izturn closed 9 months ago

izturn commented 9 months ago

Thanks for share the nice repo, I have just added the Loader to my code, the new version makes it outdated ;-), the last feature I'm missing is sliding caching, now the cache is absolute TTL, shall we add it?

phuslu commented 9 months ago

I think adding "sliding caching" will not hit performance. but seems it requires to add extra 4/8 bytes (int32/int64) to record time.Duration, it will hit the memory efficient. Let me consider...

Maybe we could considering to decrease the TTL accuracy to seconds level (uint32), then adding the sliding will also requires another uint32(even uint16).

phuslu commented 9 months ago

Another option is, just fork/copy this LRU codes to your project then modify easily -- That's is the initial motivation of this library. 😄

BTW: to simplify the repo codes, I remove bench tests and merge its code to readme and workflow yaml.

izturn commented 9 months ago

so, which option is you prefer?

phuslu commented 9 months ago

let me try option 1, hopefully nobody won't unhappy with the TTL accuracy decreasing.

phuslu commented 9 months ago

I added sliding cache support in master branch by introduce a method *Cache.SlidingGet(key), please help check

  1. hope this implementation is correct, without any misunderstandings.
  2. could please give advice/suggestion about the method naming? "SildingGet" seems not good enough.
  3. I'm still considering do accuracy decreasing by ttl/expires from int64 -> int32
izturn commented 9 months ago

I added sliding cache support in master branch by introduce a method *Cache.SlidingGet(key), please help check

1. hope this implementation is correct, without any misunderstandings.

2. could please give advice/suggestion about the method naming? "SildingGet" seems not good enough.

3. I'm still considering do accuracy decreasing by ttl/expires from int64 -> int32
  1. nice
  2. i asked the bard, it seems that the all cache implemention's Get will be sliding, maybe touchGet?
  3. i think accuracy decreasing is ok
phuslu commented 9 months ago
  1. Thanks.
  2. I rename to TouchGet and add a new method TouchGetOrLoad
  3. I decreased the time accuracy on master branch.
izturn commented 9 months ago

i think we can delay/match the Range to spec: add range over int, range over func. btw, how about a clear?

phuslu commented 9 months ago

I reverted Range method.

And for Clear, I afraid that it will introduce data race or user misunderstood/misuse, so I have no good idea to add/implement it.

phuslu commented 9 months ago

Please allow me close this issue.

Welcome to raise new issues for feature request/ideas, thanks again!