Caching policies added.

We used httpcache library to implement this. As it was not possible to support different policies, I mostly copied and modified it.
This commit is contained in:
Musab Gültekin
2019-07-07 12:18:40 +03:00
parent 0d6c2a6864
commit 90d2be2210
13 changed files with 2349 additions and 16 deletions

View File

@ -1,7 +1,7 @@
package geziyor
import (
"github.com/fpfeng/httpcache"
"github.com/geziyor/geziyor/cache"
"github.com/geziyor/geziyor/client"
"github.com/geziyor/geziyor/metrics"
"github.com/geziyor/geziyor/middleware"
@ -69,8 +69,12 @@ func NewGeziyor(opt *Options) *Geziyor {
// Client
geziyor.Client = client.NewClient(opt.MaxBodySize, opt.CharsetDetectDisabled, opt.RetryTimes, opt.RetryHTTPCodes)
if opt.Cache != nil {
geziyor.Client.Transport = &httpcache.Transport{
Transport: geziyor.Client.Transport, Cache: opt.Cache, MarkCachedResponses: true}
geziyor.Client.Transport = &cache.Transport{
Policy: opt.CachePolicy,
Transport: geziyor.Client.Transport,
Cache: opt.Cache,
MarkCachedResponses: true,
}
}
if opt.Timeout != 0 {
geziyor.Client.Timeout = opt.Timeout