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

12
cache/cache.go vendored
View File

@ -9,9 +9,15 @@ import (
) )
var ( var (
USER_CACHE_DIR, err = os.UserCacheDir()
CACHE_LIST map[[2]string]string = make(map[[2]string]string) 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 { func LoadCache(path string) error {
cacheFileContent, err := ioutil.ReadFile(path) cacheFileContent, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
@ -37,8 +43,10 @@ func GetFromCache(artist, album string) (string, error) {
} }
} }
func AddToCache(artist, album string) { func AddToCache(artist, album string) string {
CACHE_LIST[[2]string{artist, album}] = GenerateName(artist, album) fileName := CACHE_DIR + GenerateName(artist, album)
CACHE_LIST[[2]string{artist, album}] = fileName
return fileName
} }
func WriteCache(path string) { func WriteCache(path string) {