]> git.lizzy.rs Git - go-anidb.git/commitdiff
anidb: Update documentation
authorDiogo Franco (Kovensky) <diogomfranco@gmail.com>
Sun, 14 Jul 2013 15:42:42 +0000 (12:42 -0300)
committerDiogo Franco (Kovensky) <diogomfranco@gmail.com>
Sun, 14 Jul 2013 15:42:42 +0000 (12:42 -0300)
anidb.go
cache.go
filecache.go
misc.go
titlecache.go

index 812f4c4704e6d68a5366154b857d0a4d79466f74..1b69e714255c8ac729a9b42d044d9282a6a1fba1 100644 (file)
--- a/anidb.go
+++ b/anidb.go
@@ -5,6 +5,7 @@ import (
        "time"
 )
 
+// Main struct for the client, contains all non-shared state.
 type AniDB struct {
        Timeout time.Duration // Timeout for the various calls (default: 45s)
 
index fff97cbef2cf04b714d65c525c871c807cdfcf28..1f1db42ee1dcb75415a535185f8e5f4d495596a3 100644 (file)
--- a/cache.go
+++ b/cache.go
@@ -52,6 +52,11 @@ func init() {
 
 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 {
@@ -75,6 +80,7 @@ func SetCacheDir(path string) (err error) {
        return nil
 }
 
+// Returns the current cache dir.
 func GetCacheDir() (path string) {
        cache.RLock()
        defer cache.RUnlock()
index 41b59843c6439d7dd12414c9d7554b7b26a26aa4..69c8741d9d1e6a0078a5c3f968d701772edc4919 100644 (file)
@@ -80,6 +80,9 @@ func (f *File) Prefetch(adb *AniDB) <-chan *File {
        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}
 
@@ -124,6 +127,9 @@ func (adb *AniDB) FileByID(fid FID) <-chan *File {
        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}
 
diff --git a/misc.go b/misc.go
index f738d2883541b42221a10c45c06bef28e8cbd90f..22a010c1d2b7412a92dec55c19702b16bd778ecd 100644 (file)
--- a/misc.go
+++ b/misc.go
@@ -15,6 +15,7 @@ var (
        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.
index 1100df085bc1eed4c4fa23863821e7529ce8dc7a..64b10061f50933e00a56df5593bdac05c82a8a10 100644 (file)
@@ -9,7 +9,7 @@ import (
 
 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()
@@ -32,7 +32,7 @@ func TitlesUpToDate() (ok bool) {
 
 // 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() {