package repository import ( "electricity_bill_calc/cache" "time" ) func _postProcessSingle[T interface{}](instance *T, has bool, err error) (*T, error) { if err != nil { return nil, err } if has { return instance, nil } else { return nil, nil } } func _postProcessList[T interface{}](instance []*T, has bool, err error) ([]*T, error) { if err != nil { return nil, err } if has { return instance, nil } else { return nil, nil } } func cacheData[T interface{}](instance T, category string, key ...string) error { var keys = make([]string, 0) keys = append(keys, category) keys = append(keys, key...) cacheKey := cache.CacheKey("cache", keys...) if exists, _ := cache.Exists(cacheKey); exists { cache.Delete(cacheKey) } return cache.Cache(cacheKey, &instance, 5*time.Minute) } func retreiveData[T interface{}](category string, key ...string) (*T, error) { var keys = make([]string, 0) keys = append(keys, category) keys = append(keys, key...) return cache.Retreive[T](cache.CacheKey("cache", keys...)) }