Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
11d671c6
Commit
11d671c6
authored
Feb 23, 2019
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add support for memcached
parent
5ced863f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
5 deletions
+67
-5
pkg/infra/distcache/distcache.go
+4
-4
pkg/infra/distcache/distcache_test.go
+1
-1
pkg/infra/distcache/memcached_storage.go
+62
-0
No files found.
pkg/infra/distcache/distcache.go
View file @
11d671c6
...
...
@@ -39,12 +39,12 @@ func createClient(opts CacheOpts, sqlstore *sqlstore.SqlStore) cacheStorage {
}
if
opts
.
name
==
"memcache"
{
return
n
il
return
n
ewMemcacheStorage
(
"localhost:9090"
)
}
if
opts
.
name
==
"memory"
{
return
nil
}
//
if opts.name == "memory" {
//
return nil
//
}
return
newDatabaseCache
(
sqlstore
)
//&databaseCache{SQLStore: sqlstore}
}
...
...
pkg/infra/distcache/distcache_test.go
View file @
11d671c6
...
...
@@ -27,7 +27,7 @@ func createTestClient(t *testing.T, name string) cacheStorage {
}
func
TestAllCacheClients
(
t
*
testing
.
T
)
{
clients
:=
[]
string
{
"database"
,
"redis"
}
// add redis, memcache, memory
clients
:=
[]
string
{
"database"
,
"redis"
,
"memcached"
}
// add redis, memcache, memory
for
_
,
v
:=
range
clients
{
client
:=
createTestClient
(
t
,
v
)
...
...
pkg/infra/distcache/memcached_storage.go
0 → 100644
View file @
11d671c6
package
distcache
import
(
"time"
"github.com/bradfitz/gomemcache/memcache"
)
type
memcacheStorage
struct
{
c
*
memcache
.
Client
}
func
newMemcacheStorage
(
connStr
string
)
*
memcacheStorage
{
return
&
memcacheStorage
{
c
:
memcache
.
New
(
connStr
),
}
}
func
NewItem
(
sid
string
,
data
[]
byte
,
expire
int32
)
*
memcache
.
Item
{
return
&
memcache
.
Item
{
Key
:
sid
,
Value
:
data
,
Expiration
:
expire
,
}
}
// Set sets value to given key in the cache.
func
(
s
*
memcacheStorage
)
Put
(
key
string
,
val
interface
{},
expires
time
.
Duration
)
error
{
item
:=
&
Item
{
Val
:
val
}
bytes
,
err
:=
EncodeGob
(
item
)
if
err
!=
nil
{
return
err
}
memcacheItem
:=
NewItem
(
key
,
bytes
,
int32
(
expires
))
s
.
c
.
Add
(
memcacheItem
)
return
nil
}
// Get gets value by given key in the cache.
func
(
s
*
memcacheStorage
)
Get
(
key
string
)
(
interface
{},
error
)
{
i
,
err
:=
s
.
c
.
Get
(
key
)
if
err
!=
nil
{
return
nil
,
err
}
item
:=
&
Item
{}
err
=
DecodeGob
(
i
.
Value
,
item
)
if
err
!=
nil
{
return
nil
,
err
}
return
item
.
Val
,
nil
}
// Delete delete a key from the cache
func
(
s
*
memcacheStorage
)
Delete
(
key
string
)
error
{
return
s
.
c
.
Delete
(
key
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment