MCPcopy Create free account
hub / github.com/Permify/permify / setCheckKey

Method setCheckKey

internal/engines/cache/check.go:142–164  ·  view source on GitHub ↗

setCheckKey is a function to set a check key in the cache of the CheckEngineWithKeys. It takes a permission check request as a key, a permission check response as a value, and returns a boolean value indicating if the operation was successful.

(key *base.PermissionCheckRequest, value *base.PermissionCheckResponse, isRelational bool)

Source from the content-addressed store, hash-verified

140// It takes a permission check request as a key, a permission check response as a value,
141// and returns a boolean value indicating if the operation was successful.
142func (c *CheckEngineWithCache) setCheckKey(key *base.PermissionCheckRequest, value *base.PermissionCheckResponse, isRelational bool) bool {
143 // If either the key or the value is nil, return false.
144 if key == nil || value == nil {
145 return false
146 }
147
148 // Create a new xxhash object for hashing.
149 h := xxhash.New()
150
151 // Generate a key string from the permission check request and write it to the hash.
152 // If there's an error while writing to the hash, return false.
153 size, err := h.Write([]byte(engines.GenerateKey(key, isRelational)))
154 if err != nil {
155 return false
156 }
157
158 // Compute the hash sum and encode it as a hexadecimal string.
159 k := hex.EncodeToString(h.Sum(nil))
160
161 // Set the hashed key and the check result in the cache, using the size of the hashed key as an expiry.
162 // The Set method should return true if the operation was successful, so return the result.
163 return c.cache.Set(k, value.GetCan(), int64(size))
164}

Callers 2

CheckMethod · 0.95
check_test.goFile · 0.80

Calls 4

GenerateKeyFunction · 0.92
GetCanMethod · 0.80
WriteMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected