From 1014981dcb28e0aa11a70bb3d2281e50a450af3b Mon Sep 17 00:00:00 2001 From: aditya-K2 Date: Sat, 20 Nov 2021 21:38:38 +0530 Subject: [PATCH] Added Simple Helper Functions Following Functions have been added : 1. SetCacheDir : Sets the Cache Directory 2. CHANGE AddToCache the image path is now the Cache Directory + image Path --- cache/cache.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index 4dd3e1d..c4afacc 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -9,9 +9,15 @@ import ( ) var ( - CACHE_LIST map[[2]string]string = make(map[[2]string]string) + USER_CACHE_DIR, err = os.UserCacheDir() + CACHE_LIST map[[2]string]string = make(map[[2]string]string) + CACHE_DIR string = USER_CACHE_DIR ) +func SetCacheDir(path string) { + CACHE_DIR = path +} + func LoadCache(path string) error { cacheFileContent, err := ioutil.ReadFile(path) if err != nil { @@ -37,8 +43,10 @@ func GetFromCache(artist, album string) (string, error) { } } -func AddToCache(artist, album string) { - CACHE_LIST[[2]string{artist, album}] = GenerateName(artist, album) +func AddToCache(artist, album string) string { + fileName := CACHE_DIR + GenerateName(artist, album) + CACHE_LIST[[2]string{artist, album}] = fileName + return fileName } func WriteCache(path string) {