-
Notifications
You must be signed in to change notification settings - Fork 146
Conversation
Codecov Report
@@ Coverage Diff @@
## master #567 +/- ##
==========================================
+ Coverage 49.37% 50.70% +1.33%
==========================================
Files 81 82 +1
Lines 1511 1552 +41
Branches 97 97
==========================================
+ Hits 746 787 +41
Misses 731 731
Partials 34 34
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, Tom! Please address my comments
} | ||
|
||
// Node defines a node in doubly linked list | ||
type Node struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest you using container/list
package, as it provides all required functionality:
// MoveToFront moves element e to the front of list l.
MoveToFront
// PushFront inserts a new element e with value v at the front of list l and returns e.
PushFront
// PushBack inserts a new element e with value v at the back of list l and returns e.
PushBack
// Back returns the last element of list l or nil if the list is empty
Back
Maybe even use already ready solution https://github.com/golang/groupcache/blob/master/lru/lru.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alldroll I recommend implementing everything ourselves to remove dependency on external packages and to learn the internals
// Cache stores key-value pair in memory, | ||
// it uses classic implementation of LRU cache | ||
type Cache struct { | ||
Head *Node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you declare fields as public?
Let's create a interface for Cache so that we can replace the implementation with either in memory cache, Redis or distributed cache. |
Our cache should support all caching strategy and eviction algorithms mentioned here: s/cache |
Closing this PR because cache will be redesigned to support in-memory cache, Redis, and distributed cache. |
New Behavior
Description
Added LRU cache implementation.
User should be able to search the public and the private short links they created. In order to support that, we add RESTful API to search for all urls created by a given user. In order to support caching URLs to reduce traffic to DB, we need to add cache.