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
This commit is contained in:
aditya-K2 2021-11-20 21:38:38 +05:30
parent 42832491d0
commit 1014981dcb
1 changed files with 11 additions and 3 deletions

14
cache/cache.go vendored
View File

@ -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) {