Skip to content
This repository has been archived by the owner on Oct 17, 2020. It is now read-only.

Added LRU cache implementation #567

Closed
wants to merge 4 commits into from
Closed

Conversation

dawntomm
Copy link
Contributor

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.

@dawntomm dawntomm self-assigned this Mar 17, 2020
@dawntomm dawntomm added this to In progress in Short 1.0 via automation Mar 17, 2020
@dawntomm dawntomm added this to the 03/14 - 03/20 milestone Mar 17, 2020
@dawntomm dawntomm removed this from In progress in Short 1.0 Mar 17, 2020
@dawntomm dawntomm added this to In progress in Short 1.0 via automation Mar 17, 2020
@dawntomm dawntomm linked an issue Mar 17, 2020 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Mar 17, 2020

Codecov Report

Merging #567 into master will increase coverage by 1.33%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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              
Flag Coverage Δ
#golang 80.00% <100.00%> (+0.89%) ⬆️
#typescript 3.85% <ø> (ø)
Impacted Files Coverage Δ
backend/app/adapter/cache/cache.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dd8d778...0931862. Read the comment docs.

Copy link
Contributor

@alldroll alldroll left a 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 {
Copy link
Contributor

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

Copy link
Member

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
Copy link
Contributor

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?

Short 1.0 automation moved this from In progress to In Review Mar 17, 2020
@magicoder10
Copy link
Member

Let's create a interface for Cache so that we can replace the implementation with either in memory cache, Redis or distributed cache.

@magicoder10
Copy link
Member

Our cache should support all caching strategy and eviction algorithms mentioned here: s/cache

@magicoder10
Copy link
Member

Closing this PR because cache will be redesigned to support in-memory cache, Redis, and distributed cache.

Short 1.0 automation moved this from In Review to Done Mar 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
Short 1.0
  
Done
Development

Successfully merging this pull request may close these issues.

Create RESTful search API in Go
3 participants