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
7aeab0a2
Commit
7aeab0a2
authored
Mar 11, 2019
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use `Get` instead of `Find`
parent
b2967fbb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
14 deletions
+12
-14
pkg/infra/remotecache/database_storage.go
+11
-11
scripts/circle-test-cache-servers.sh
+1
-3
No files found.
pkg/infra/remotecache/database_storage.go
View file @
7aeab0a2
...
...
@@ -47,24 +47,24 @@ func (dc *databaseCache) internalRunGC() {
}
func
(
dc
*
databaseCache
)
Get
(
key
string
)
(
interface
{},
error
)
{
cacheHits
:=
[]
CacheData
{}
sess
:=
dc
.
SQLStore
.
NewSession
()
defer
sess
.
Close
()
err
:=
sess
.
Where
(
"cache_key= ?"
,
key
)
.
Find
(
&
cacheHits
)
cacheHit
:=
CacheData
{}
session
:=
dc
.
SQLStore
.
NewSession
()
defer
session
.
Close
()
exist
,
err
:=
session
.
Where
(
"cache_key= ?"
,
key
)
.
Get
(
&
cacheHit
)
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
cacheHits
)
==
0
{
if
!
exist
{
return
nil
,
ErrCacheItemNotFound
}
cacheHit
:=
cacheHits
[
0
]
if
cacheHit
.
Expires
>
0
{
existedButExpired
:=
getTime
()
.
Unix
()
-
cacheHit
.
CreatedAt
>=
cacheHit
.
Expires
if
existedButExpired
{
dc
.
Delete
(
key
)
_
=
dc
.
Delete
(
key
)
//ignore this error since we will return `ErrCacheItemNotFound` anyway
return
nil
,
ErrCacheItemNotFound
}
}
...
...
@@ -99,9 +99,11 @@ func (dc *databaseCache) Set(key string, value interface{}, expire time.Duration
// insert or update depending on if item already exist
if
has
{
_
,
err
=
session
.
Exec
(
`UPDATE cache_data SET data=?, created=?, expire=? WHERE cache_key='?'`
,
data
,
getTime
()
.
Unix
(),
expiresAtEpoch
,
key
)
sql
:=
`UPDATE cache_data SET data=?, created=?, expire=? WHERE cache_key='?'`
_
,
err
=
session
.
Exec
(
sql
,
data
,
getTime
()
.
Unix
(),
expiresAtEpoch
,
key
)
}
else
{
_
,
err
=
session
.
Exec
(
`INSERT INTO cache_data (cache_key,data,created_at,expires) VALUES(?,?,?,?)`
,
key
,
data
,
getTime
()
.
Unix
(),
expiresAtEpoch
)
sql
:=
`INSERT INTO cache_data (cache_key,data,created_at,expires) VALUES(?,?,?,?)`
_
,
err
=
session
.
Exec
(
sql
,
key
,
data
,
getTime
()
.
Unix
(),
expiresAtEpoch
)
}
return
err
...
...
@@ -120,5 +122,3 @@ type CacheData struct {
Expires
int64
CreatedAt
int64
}
// func (cd CacheData) TableName() string { return "cache_data" }
scripts/circle-test-cache-servers.sh
View file @
7aeab0a2
...
...
@@ -11,8 +11,6 @@ function exit_if_fail {
}
echo
"running redis and memcache tests"
#set -e
#time for d in $(go list ./pkg/...); do
time
exit_if_fail go
test
-tags
=
redis ./pkg/infra/remotecache/...
time
exit_if_fail go
test
-tags
=
memcached ./pkg/infra/remotecache/...
#done
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