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
d2125545
Commit
d2125545
authored
2 years ago
by
Yordan Kinkov
Browse files
Options
Downloads
Patches
Plain Diff
#3
change SET endpoint payload type to json
parent
c379431a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!3
Create SET cache endpoint
Pipeline
#49801
passed with stage
in 43 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
design/types.go
+1
-1
1 addition, 1 deletion
design/types.go
internal/service/cache/service.go
+10
-2
10 additions, 2 deletions
internal/service/cache/service.go
with
11 additions
and
3 deletions
design/types.go
+
1
−
1
View file @
d2125545
...
...
@@ -11,7 +11,7 @@ var CacheGetRequest = Type("CacheGetRequest", func() {
})
var
CacheSetRequest
=
Type
(
"CacheSetRequest"
,
func
()
{
Field
(
1
,
"data"
,
Bytes
)
Field
(
1
,
"data"
,
Any
)
Field
(
2
,
"key"
,
String
)
Field
(
3
,
"namespace"
,
String
)
Field
(
4
,
"scope"
,
String
)
// Initial implementation with a single scope
...
...
This diff is collapsed.
Click to expand it.
internal/service/cache/service.go
+
10
−
2
View file @
d2125545
...
...
@@ -2,6 +2,7 @@ package cache
import
(
"context"
"encoding/json"
"fmt"
"time"
...
...
@@ -51,7 +52,8 @@ func (s *Service) Get(ctx context.Context, req *cache.CacheGetRequest) ([]byte,
func
(
s
*
Service
)
Set
(
ctx
context
.
Context
,
req
*
cache
.
CacheSetRequest
)
error
{
var
operation
=
zap
.
String
(
"operation"
,
"set"
)
if
req
.
Key
==
""
||
req
.
Namespace
==
""
||
req
.
Scope
==
""
||
len
(
req
.
Data
)
==
0
{
if
req
.
Key
==
""
||
req
.
Namespace
==
""
||
req
.
Scope
==
""
||
len
(
req
.
Data
.
(
map
[
string
]
interface
{}))
==
0
{
s
.
logger
.
Error
(
"bad request: missing key or namespace or scope or data"
,
operation
)
return
errors
.
New
(
errors
.
BadRequest
,
"bad request"
)
}
...
...
@@ -60,7 +62,13 @@ func (s *Service) Set(ctx context.Context, req *cache.CacheSetRequest) error {
// create key from the input fields
key
:=
makeCacheKey
(
req
.
Namespace
,
req
.
Scope
,
req
.
Key
)
if
err
:=
s
.
cache
.
Set
(
ctx
,
key
,
req
.
Data
,
0
);
err
!=
nil
{
// encode payload to json bytes for storing in cache
value
,
err
:=
json
.
Marshal
(
req
.
Data
)
if
err
!=
nil
{
s
.
logger
.
Error
(
"error encode payload to json"
,
zap
.
Error
(
err
),
operation
)
return
errors
.
New
(
"error encode payload to json"
,
err
)
}
if
err
:=
s
.
cache
.
Set
(
ctx
,
key
,
value
,
0
);
err
!=
nil
{
s
.
logger
.
Error
(
"error setting value in cache"
,
zap
.
Error
(
err
),
operation
)
return
errors
.
New
(
"error setting 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