Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cache service

Implemented a sharded in-memory cache service with TTL expiry and CLOCK eviction for size constraints.

CLOCK eviction algorithm: once the size of a shard is full, to evict, rotate through all entries until we find one that hasn't been referenced since the last time we checked it ("second-chance algorithm").

True LRU eviction requires mutating state per shard on every read to maintain least recently used within a doubly linked list, which offers O(1) eviction, which enables read contention.

CLOCK approximates LRU with a reference/read flag which is set when not already set, keeping all reads lock-free.

A background sweeper is implemented to clean the expired entries on TTL, which will run periodically, locking only one shard at a time.

To Run locally

under /cache-service folder, run make target run using command

make run 

About

A key value cache service written in Go

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages