+ config: add cache size settings
This commit is contained in:
parent
c2dacd32d1
commit
81303b5db7
|
@ -26,7 +26,6 @@ import (
|
||||||
"golang.org/x/net/publicsuffix"
|
"golang.org/x/net/publicsuffix"
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultCacheSize = 64 * 1024 // in number of elements
|
|
||||||
const defaultCacheTime = 30 * time.Minute
|
const defaultCacheTime = 30 * time.Minute
|
||||||
|
|
||||||
const defaultHTTPTimeout = 5 * time.Minute
|
const defaultHTTPTimeout = 5 * time.Minute
|
||||||
|
@ -56,6 +55,10 @@ type Config struct {
|
||||||
SafeBrowsingEnabled bool `yaml:"safebrowsing_enabled"`
|
SafeBrowsingEnabled bool `yaml:"safebrowsing_enabled"`
|
||||||
ResolverAddress string // DNS server address
|
ResolverAddress string // DNS server address
|
||||||
|
|
||||||
|
SafeBrowsingCacheSize int `yaml:"safebrowsing_cache_size"`
|
||||||
|
SafeSearchCacheSize int `yaml:"safesearch_cache_size"`
|
||||||
|
ParentalCacheSize int `yaml:"parental_cache_size"`
|
||||||
|
|
||||||
// Filtering callback function
|
// Filtering callback function
|
||||||
FilterHandler func(clientAddr string, settings *RequestFilteringSettings) `yaml:"-"`
|
FilterHandler func(clientAddr string, settings *RequestFilteringSettings) `yaml:"-"`
|
||||||
}
|
}
|
||||||
|
@ -732,13 +735,13 @@ func New(c *Config, filters map[int]string) *Dnsfilter {
|
||||||
if c != nil {
|
if c != nil {
|
||||||
// initialize objects only once
|
// initialize objects only once
|
||||||
if gctx.safebrowsingCache == nil {
|
if gctx.safebrowsingCache == nil {
|
||||||
gctx.safebrowsingCache = gcache.New(defaultCacheSize).LRU().Expiration(defaultCacheTime).Build()
|
gctx.safebrowsingCache = gcache.New(c.SafeBrowsingCacheSize).LRU().Expiration(defaultCacheTime).Build()
|
||||||
}
|
}
|
||||||
if gctx.safeSearchCache == nil {
|
if gctx.safeSearchCache == nil {
|
||||||
gctx.safeSearchCache = gcache.New(defaultCacheSize).LRU().Expiration(defaultCacheTime).Build()
|
gctx.safeSearchCache = gcache.New(c.SafeSearchCacheSize).LRU().Expiration(defaultCacheTime).Build()
|
||||||
}
|
}
|
||||||
if gctx.parentalCache == nil {
|
if gctx.parentalCache == nil {
|
||||||
gctx.parentalCache = gcache.New(defaultCacheSize).LRU().Expiration(defaultCacheTime).Build()
|
gctx.parentalCache = gcache.New(c.ParentalCacheSize).LRU().Expiration(defaultCacheTime).Build()
|
||||||
}
|
}
|
||||||
if len(c.ResolverAddress) != 0 && gctx.dialCache == nil {
|
if len(c.ResolverAddress) != 0 && gctx.dialCache == nil {
|
||||||
gctx.dialCache = gcache.New(maxDialCacheSize).LRU().Expiration(defaultCacheTime).Build()
|
gctx.dialCache = gcache.New(maxDialCacheSize).LRU().Expiration(defaultCacheTime).Build()
|
||||||
|
|
|
@ -205,6 +205,10 @@ func initConfig() {
|
||||||
// also change the default config
|
// also change the default config
|
||||||
config.DNS.UpstreamDNS = defaultDNS
|
config.DNS.UpstreamDNS = defaultDNS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config.DNS.SafeBrowsingCacheSize = 64 * 1024
|
||||||
|
config.DNS.SafeSearchCacheSize = 64 * 1024
|
||||||
|
config.DNS.ParentalCacheSize = 64 * 1024
|
||||||
}
|
}
|
||||||
|
|
||||||
// getConfigFilename returns path to the current config file
|
// getConfigFilename returns path to the current config file
|
||||||
|
|
Loading…
Reference in New Issue