"time"
)
+// Main struct for the client, contains all non-shared state.
type AniDB struct {
Timeout time.Duration // Timeout for the various calls (default: 45s)
var cache cacheDir
+// Sets the cache directory to the given path.
+//
+// go-anidb needs a valid cache directory to function, so, during module
+// initialization, it uses os.TempDir() to set a default cache dir.
+// go-anidb panics if it's unable to set the default cache dir.
func SetCacheDir(path string) (err error) {
m := cache.RWMutex
if m == nil {
return nil
}
+// Returns the current cache dir.
func GetCacheDir() (path string) {
cache.RLock()
defer cache.RUnlock()
return ch
}
+// Returns the File from the cache if possible.
+//
+// If the File is stale, then retrieves the File through the UDP API.
func (adb *AniDB) FileByID(fid FID) <-chan *File {
keys := []cacheKey{"fid", fid}
return ch
}
+// Returns the File from the cache if possible.
+//
+// If the File is stale, then retrieves the File through the UDP API.
func (adb *AniDB) FileByEd2kSize(ed2k string, size int64) <-chan *File {
keys := []cacheKey{"fid", "by-ed2k", ed2k, size}
GroupCacheDuration = 4 * DefaultCacheDuration // They don't change that often.
FileCacheDuration = 8 * DefaultCacheDuration // These change even less often.
+ // Used when a request uses a non-existing key (AID, ed2k+size, etc)
InvalidKeyCacheDuration = 1 * time.Hour
// Used when the UDP API Anime query fails, but the HTTP API query succeeds.
var titlesDB = &titles.TitlesDatabase{}
-// Reloads titles from the cache.
+// Loads the database from anime-titles.dat.gz in the cache dir.
func RefreshTitles() error {
flock := lockFile(cachePath("anime-titles.dat.gz"))
flock.Lock()
// Downloads a new anime-titles database if the database is outdated.
//
-// Caches the contents on memory, which gets saved by DumpCaches.
+// Saves the database as anime-titles.dat.gz in the cache dir.
func UpdateTitles() error {
// too new, no need to update
if TitlesUpToDate() {