Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
cache
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gaia-X
Trust Services API
cache
Commits
0b519ce1
Commit
0b519ce1
authored
2 years ago
by
Yordan Kinkov
Browse files
Options
Downloads
Patches
Plain Diff
#1
Add cache TTL as optional parameter on set endpoints
parent
a2a9bff3
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
design/design.go
+6
-0
6 additions, 0 deletions
design/design.go
design/types.go
+1
-0
1 addition, 0 deletions
design/types.go
internal/service/cache/service.go
+7
-3
7 additions, 3 deletions
internal/service/cache/service.go
with
14 additions
and
3 deletions
design/design.go
+
6
−
0
View file @
0b519ce1
...
...
@@ -83,6 +83,9 @@ var _ = Service("cache", func() {
Header
(
"scope:x-cache-scope"
,
String
,
"Cache entry scope"
,
func
()
{
Example
(
"administration"
)
})
Header
(
"ttl:x-cache-ttl"
,
Int
,
"Cache entry TTL in seconds"
,
func
()
{
Example
(
60
)
})
Body
(
"data"
)
Response
(
StatusCreated
)
...
...
@@ -107,6 +110,9 @@ var _ = Service("cache", func() {
Header
(
"scope:x-cache-scope"
,
String
,
"Cache entry scope"
,
func
()
{
Example
(
"administration"
)
})
Header
(
"ttl:x-cache-ttl"
,
Int
,
"Cache entry TTL in seconds"
,
func
()
{
Example
(
60
)
})
Body
(
"data"
)
Response
(
StatusOK
)
...
...
This diff is collapsed.
Click to expand it.
design/types.go
+
1
−
0
View file @
0b519ce1
...
...
@@ -15,5 +15,6 @@ var CacheSetRequest = Type("CacheSetRequest", func() {
Field
(
2
,
"key"
,
String
)
Field
(
3
,
"namespace"
,
String
)
Field
(
4
,
"scope"
,
String
)
// Initial implementation with a single scope
Field
(
5
,
"ttl"
,
Int
)
Required
(
"data"
,
"key"
)
})
This diff is collapsed.
Click to expand it.
internal/service/cache/service.go
+
7
−
3
View file @
0b519ce1
...
...
@@ -73,8 +73,6 @@ func (s *Service) Set(ctx context.Context, req *cache.CacheSetRequest) error {
return
errors
.
New
(
errors
.
BadRequest
,
"missing key"
)
}
// TODO(kinkov): issue #3 - evaluate key metadata (key, namespace and scope) and set TTL over a policy execution
// create key from the input fields
key
:=
makeCacheKey
(
req
.
Key
,
req
.
Namespace
,
req
.
Scope
)
// encode payload to json bytes for storing in cache
...
...
@@ -84,7 +82,13 @@ func (s *Service) Set(ctx context.Context, req *cache.CacheSetRequest) error {
return
errors
.
New
(
errors
.
BadRequest
,
"cannot encode payload to json"
,
err
)
}
if
err
:=
s
.
cache
.
Set
(
ctx
,
key
,
value
,
0
);
err
!=
nil
{
// set cache ttl if provided in request
var
ttl
time
.
Duration
if
req
.
TTL
!=
nil
{
ttl
=
time
.
Duration
(
*
req
.
TTL
)
*
time
.
Second
}
if
err
:=
s
.
cache
.
Set
(
ctx
,
key
,
value
,
ttl
);
err
!=
nil
{
logger
.
Error
(
"error storing value in cache"
,
zap
.
Error
(
err
))
return
errors
.
New
(
"error storing value in cache"
,
err
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment