aboutsummaryrefslogtreecommitdiff
path: root/cache.go
diff options
context:
space:
mode:
Diffstat (limited to 'cache.go')
-rw-r--r--cache.go17
1 files changed, 5 insertions, 12 deletions
diff --git a/cache.go b/cache.go
index 12c7b74..73b4d58 100644
--- a/cache.go
+++ b/cache.go
@@ -1,5 +1,5 @@
-// SPDX-FileCopyrightText: 2025 M. Shulhan <ms@kilabit.info>
// SPDX-License-Identifier: GPL-3.0-only
+// SPDX-FileCopyrightText: 2025 M. Shulhan <ms@kilabit.info>
package jarink
@@ -12,13 +12,6 @@ import (
"git.sr.ht/~shulhan/jarink/internal"
)
-// ScannedLink store information about the link.
-type ScannedLink struct {
- Url string `json:"url"`
- Size int64 `json:"size"`
- ResponseCode int `json:"response_code"`
-}
-
// Cache store external links that has been scanned, to minize
// request to the same URL in the future.
// The cache is stored as JSON file under user's cache directory, inside
@@ -26,7 +19,7 @@ type ScannedLink struct {
// For example, in Linux it should be "$HOME/.cache/jarink/cache.json".
// See [os.UserCacheDir] for location specific to operating system.
type Cache struct {
- ScannedLinks map[string]*ScannedLink `json:"scanned_links"`
+ ScannedLinks map[string]*Link `json:"scanned_links"`
file string
mtx sync.Mutex
}
@@ -36,7 +29,7 @@ func LoadCache() (cache *Cache, err error) {
var logp = `LoadCache`
cache = &Cache{
- ScannedLinks: map[string]*ScannedLink{},
+ ScannedLinks: map[string]*Link{},
}
cache.file, err = internal.CacheFile()
@@ -62,7 +55,7 @@ func LoadCache() (cache *Cache, err error) {
}
// Get return the scanned link information by url.
-func (cache *Cache) Get(url string) (scannedLink *ScannedLink) {
+func (cache *Cache) Get(url string) (scannedLink *Link) {
cache.mtx.Lock()
scannedLink = cache.ScannedLinks[url]
cache.mtx.Unlock()
@@ -95,7 +88,7 @@ func (cache *Cache) Set(url string, respCode int, size int64) {
if scannedLink != nil {
return
}
- scannedLink = &ScannedLink{
+ scannedLink = &Link{
Url: url,
Size: size,
ResponseCode: respCode,