2017-04-03 19:00:38 +05:00
|
|
|
package srnd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CacheInterface interface {
|
|
|
|
RegenAll()
|
|
|
|
RegenFrontPage()
|
2017-04-04 16:48:45 +05:00
|
|
|
RegenOnModEvent(newsgroup, msgid, root string, page int)
|
2017-04-03 19:00:38 +05:00
|
|
|
RegenerateBoard(group string)
|
|
|
|
Regen(msg ArticleEntry)
|
|
|
|
|
|
|
|
DeleteThreadMarkup(root_post_id string)
|
|
|
|
DeleteBoardMarkup(group string)
|
|
|
|
|
|
|
|
Start()
|
|
|
|
Close()
|
|
|
|
|
|
|
|
GetThreadChan() chan ArticleEntry
|
|
|
|
GetGroupChan() chan groupRegenRequest
|
|
|
|
GetHandler() http.Handler
|
|
|
|
|
|
|
|
SetRequireCaptcha(required bool)
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO only pass needed config
|
|
|
|
func NewCache(cache_type, host, port, user, password string, cache_config, config map[string]string, db Database, store ArticleStore) CacheInterface {
|
|
|
|
prefix := config["prefix"]
|
|
|
|
webroot := config["webroot"]
|
|
|
|
threads := mapGetInt(config, "regen_threads", 1)
|
|
|
|
name := config["name"]
|
|
|
|
attachments := mapGetInt(config, "allow_files", 1) == 1
|
|
|
|
|
|
|
|
if cache_type == "file" {
|
|
|
|
return NewFileCache(prefix, webroot, name, threads, attachments, db, store)
|
|
|
|
}
|
|
|
|
if cache_type == "null" {
|
|
|
|
return NewNullCache(prefix, webroot, name, attachments, db, store)
|
|
|
|
}
|
|
|
|
if cache_type == "varnish" {
|
|
|
|
url := cache_config["url"]
|
|
|
|
bind_addr := cache_config["bind"]
|
|
|
|
return NewVarnishCache(url, bind_addr, prefix, webroot, name, attachments, db, store)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Fatalf("invalid cache type: %s", cache_type)
|
|
|
|
return nil
|
|
|
|
}
|