-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from nastiausenko/feature/original-link-redirect
Add caching for short links in redirect controller
- Loading branch information
Showing
2 changed files
with
44 additions
and
5 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/com/linkurlshorter/urlshortener/redirect/LinkCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.linkurlshorter.urlshortener.redirect; | ||
|
||
import com.linkurlshorter.urlshortener.link.Link; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class LinkCache { | ||
|
||
private final Map<String, Link> cache = new HashMap<>(); | ||
|
||
public boolean containsShortLink(String shortLink) { | ||
return cache.containsKey(shortLink); | ||
} | ||
|
||
public Link getByShortLink(String shortLink) { | ||
return cache.get(shortLink); | ||
} | ||
|
||
public void putLink(String shortLink, Link link) { | ||
cache.put(shortLink, link); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters