Skip to content

Add httpBackend cache response callback#574

Merged
asciimoo merged 1 commit intogocolly:masterfrom
slashapp:master
Mar 15, 2021
Merged

Add httpBackend cache response callback#574
asciimoo merged 1 commit intogocolly:masterfrom
slashapp:master

Conversation

@slashapp
Copy link

The checkHeadersFunc is called before response cached body, it can check cache expire or force cache invalidation.

c.OnResponseHeaders(func(r *colly.Response) {
	respTime, err := time.Parse(http.TimeFormat, r.Headers.Get("Date"))
	if err != nil || time.Now().UTC().Sub(respTime) > maxAge {
		r.StatusCode = 510 // invalidate the cache
	}
})

The checkHeadersFunc is called before response cached body,
it can check cache expire or force cache invalidation.
Copy link
Member

@asciimoo asciimoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@asciimoo asciimoo merged commit 34f9af5 into gocolly:master Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants