-
Notifications
You must be signed in to change notification settings - Fork 49
/
surrogate.go
83 lines (80 loc) · 4.18 KB
/
surrogate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package surrogate
// The Surrogate key system is like the ykey one in Varnish and the same as Fastly.
// You can send a PURGE request on the Souin API endpoint with the Surrogate header to invalidate the filled keys.
// The Surrogate header CAN contains one or multiple keys separated by a comma as mentioned in the RFC.
// e.g.
// Given the Surrogate-Key data as
// |---------------|-----------------------------------------------------------------------------------|
// | Surrogate Key | URLs |
// |---------------|-----------------------------------------------------------------------------------|
// | GROUP_KEY_ONE | http://domain.com/,http://domain.com/1,http://domain.com/2,http://domain.com/4 |
// | GROUP_KEY_TWO | http://domain.com/1,http://domain.com/2,http://domain.com/3,http://domain.com/xyz |
// |---------------|-----------------------------------------------------------------------------------|
// When I send a purge request to /souin-api/souin with the headers
// Surrogate-Key: GROUP_KEY_ONE
// Then the cache will be purged for the list
// * http://domain.com/
// * http://domain.com/1
// * http://domain.com/2
// * http://domain.com/4
// And the data in the Surrogate-Key table storage will contain
// |---------------|-------------------------------------------|
// | Surrogate Key | URLs |
// |---------------|-------------------------------------------|
// | GROUP_KEY_ONE | |
// | GROUP_KEY_TWO | http://domain.com/3,http://domain.com/xyz |
// |---------------|-------------------------------------------|
//
// Another example
// Given the Surrogate-Key data as
// |---------------|-----------------------------------------------------------------------------------|
// | Surrogate Key | URLs |
// |---------------|-----------------------------------------------------------------------------------|
// | GROUP_KEY_ONE | http://domain.com/,http://domain.com/1,http://domain.com/2,http://domain.com/4 |
// | GROUP_KEY_TWO | http://domain.com/1,http://domain.com/2,http://domain.com/3,http://domain.com/xyz |
// |---------------|-----------------------------------------------------------------------------------|
// When I send a purge request to /souin-api/souin
// Surrogate-Key: GROUP_KEY_ONE, GROUP_KEY_TWO
// Then the cache will be purged for the list
// * http://domain.com/
// * http://domain.com/1
// * http://domain.com/2
// * http://domain.com/4
// * http://domain.com/xyz
// And the data in the Surrogate-Key table storage will contain
// |---------------|------|
// | Surrogate Key | URLs |
// |---------------|------|
// | GROUP_KEY_ONE | |
// | GROUP_KEY_TWO | |
// |---------------|------|
//
// If the Surrogate Storage is configured with the dynamic boolean value, then it will handle and store all Surrogate-Key
// sent by the server on a specific resource.
// Given the Surrogate-Key data as
// |---------------|------|
// | Surrogate Key | URLs |
// |---------------|------|
// | GROUP_KEY_ONE | |
// | GROUP_KEY_TWO | |
// |---------------|------|
// When you send a request to /service_1/my_first_resource
// Then the server response contains the following headers
// Surrogate-Key: GROUP_KEY_NEW, another_one
// Then the data in the Surrogate-Key table storage will contain
// |---------------|------------------------------|
// | Surrogate Key | URLs |
// |---------------|------------------------------|
// | another_one | /service_1/my_first_resource |
// | GROUP_KEY_NEW | /service_1/my_first_resource |
// | GROUP_KEY_ONE | |
// | GROUP_KEY_TWO | |
// |---------------|------------------------------|
import (
"github.com/darkweak/souin/configurationtypes"
"github.com/darkweak/souin/pkg/surrogate/providers"
)
// InitializeSurrogate will initialize the Surrogate-Key storage system
func InitializeSurrogate(configurationInterface configurationtypes.AbstractConfigurationInterface) providers.SurrogateInterface {
return providers.SurrogateFactory(configurationInterface)
}