FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
httpsms/api/pkg/cache/memory_cache.go at main · NdoleStudio/httpsms · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
NdoleStudio
/
httpsms
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
783
Star
4.6k
Code
Issues
0
Pull requests
3
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
httpsms
/
api
/
pkg
/
cache
/
memory_cache.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
46 lines (37 loc) · 1.07 KB
Breadcrumbs
httpsms
/
api
/
pkg
/
cache
/
memory_cache.go
Copy path
File metadata and controls
46 lines (37 loc) · 1.07 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package
cache
import
(
"context"
"time"
"github.com/NdoleStudio/httpsms/pkg/telemetry"
"github.com/NdoleStudio/stacktrace"
ttlCache
"github.com/patrickmn/go-cache"
)
// memoryCache is the Cache implementation in memory
type
memoryCache
struct
{
tracer
telemetry.
Tracer
store
*
ttlCache.
Cache
}
// NewMemoryCache creates a new instance of memoryCache
func
NewMemoryCache
(
tracer
telemetry.
Tracer
,
store
*
ttlCache.
Cache
)
Cache
{
return
&
memoryCache
{
tracer
:
tracer
,
store
:
store
,
}
}
// Get an item from the redis cache
func
(
cache
*
memoryCache
)
Get
(
ctx
context.
Context
,
key
string
) (
value
string
,
err
error
) {
ctx
,
span
:=
cache
.
tracer
.
Start
(
ctx
)
defer
span
.
End
()
response
,
ok
:=
cache
.
store
.
Get
(
key
)
if
!
ok
{
return
""
,
stacktrace
.
NewErrorf
(
"no item found in cache with key [%s]"
,
key
)
}
return
response
.(
string
),
nil
}
// Set an item in the redis cache
func
(
cache
*
memoryCache
)
Set
(
ctx
context.
Context
,
key
string
,
value
string
,
ttl
time.
Duration
)
error
{
ctx
,
span
:=
cache
.
tracer
.
Start
(
ctx
)
defer
span
.
End
()
cache
.
store
.
Set
(
key
,
value
,
ttl
)
return
nil
}
Back
|
FazBrowse Home
|
New Git URL