Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
f74d1b7b
Unverified
Commit
f74d1b7b
authored
Feb 10, 2023
by
boojack
Committed by
GitHub
Feb 10, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: remove resource cache (#1059)
parent
a004dcf3
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
32 additions
and
71 deletions
+32
-71
cache.go
api/cache.go
+0
-22
cache.go
store/cache.go
+16
-6
memo.go
store/memo.go
+5
-5
resource.go
store/resource.go
+0
-26
shortcut.go
store/shortcut.go
+5
-5
store.go
store/store.go
+1
-2
user.go
store/user.go
+5
-5
No files found.
api/cache.go
deleted
100644 → 0
View file @
a004dcf3
package
api
// CacheNamespace is the type of a cache.
type
CacheNamespace
string
const
(
// UserCache is the cache type of users.
UserCache
CacheNamespace
=
"u"
// MemoCache is the cache type of memos.
MemoCache
CacheNamespace
=
"m"
// ShortcutCache is the cache type of shortcuts.
ShortcutCache
CacheNamespace
=
"s"
// ResourceCache is the cache type of resources.
ResourceCache
CacheNamespace
=
"r"
)
// CacheService is the service for caches.
type
CacheService
interface
{
FindCache
(
namespace
CacheNamespace
,
id
int
,
entry
interface
{})
(
bool
,
error
)
UpsertCache
(
namespace
CacheNamespace
,
id
int
,
entry
interface
{})
error
DeleteCache
(
namespace
CacheNamespace
,
id
int
)
}
store/cache.go
View file @
f74d1b7b
...
...
@@ -7,13 +7,11 @@ import (
"fmt"
"github.com/VictoriaMetrics/fastcache"
"github.com/usememos/memos/api"
)
var
(
// 64 MiB.
cacheSize
=
1024
*
1024
*
64
_
api
.
CacheService
=
(
*
CacheService
)(
nil
)
cacheSize
=
1024
*
1024
*
64
)
// CacheService implements a cache.
...
...
@@ -21,6 +19,18 @@ type CacheService struct {
cache
*
fastcache
.
Cache
}
// CacheNamespace is the type of a cache.
type
CacheNamespace
string
const
(
// UserCache is the cache type of users.
UserCache
CacheNamespace
=
"u"
// MemoCache is the cache type of memos.
MemoCache
CacheNamespace
=
"m"
// ShortcutCache is the cache type of shortcuts.
ShortcutCache
CacheNamespace
=
"s"
)
// NewCacheService creates a cache service.
func
NewCacheService
()
*
CacheService
{
return
&
CacheService
{
...
...
@@ -29,7 +39,7 @@ func NewCacheService() *CacheService {
}
// FindCache finds the value in cache.
func
(
s
*
CacheService
)
FindCache
(
namespace
api
.
CacheNamespace
,
id
int
,
entry
interface
{})
(
bool
,
error
)
{
func
(
s
*
CacheService
)
FindCache
(
namespace
CacheNamespace
,
id
int
,
entry
interface
{})
(
bool
,
error
)
{
buf1
:=
[]
byte
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
}
binary
.
LittleEndian
.
PutUint64
(
buf1
,
uint64
(
id
))
...
...
@@ -46,7 +56,7 @@ func (s *CacheService) FindCache(namespace api.CacheNamespace, id int, entry int
}
// UpsertCache upserts the value to cache.
func
(
s
*
CacheService
)
UpsertCache
(
namespace
api
.
CacheNamespace
,
id
int
,
entry
interface
{})
error
{
func
(
s
*
CacheService
)
UpsertCache
(
namespace
CacheNamespace
,
id
int
,
entry
interface
{})
error
{
buf1
:=
[]
byte
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
}
binary
.
LittleEndian
.
PutUint64
(
buf1
,
uint64
(
id
))
...
...
@@ -61,7 +71,7 @@ func (s *CacheService) UpsertCache(namespace api.CacheNamespace, id int, entry i
}
// DeleteCache deletes the cache.
func
(
s
*
CacheService
)
DeleteCache
(
namespace
api
.
CacheNamespace
,
id
int
)
{
func
(
s
*
CacheService
)
DeleteCache
(
namespace
CacheNamespace
,
id
int
)
{
buf1
:=
[]
byte
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
}
binary
.
LittleEndian
.
PutUint64
(
buf1
,
uint64
(
id
))
...
...
store/memo.go
View file @
f74d1b7b
...
...
@@ -102,7 +102,7 @@ func (s *Store) CreateMemo(ctx context.Context, create *api.MemoCreate) (*api.Me
return
nil
,
FormatError
(
err
)
}
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
MemoCache
,
memoRaw
.
ID
,
memoRaw
);
err
!=
nil
{
if
err
:=
s
.
cache
.
UpsertCache
(
MemoCache
,
memoRaw
.
ID
,
memoRaw
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -130,7 +130,7 @@ func (s *Store) PatchMemo(ctx context.Context, patch *api.MemoPatch) (*api.Memo,
return
nil
,
FormatError
(
err
)
}
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
MemoCache
,
memoRaw
.
ID
,
memoRaw
);
err
!=
nil
{
if
err
:=
s
.
cache
.
UpsertCache
(
MemoCache
,
memoRaw
.
ID
,
memoRaw
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -170,7 +170,7 @@ func (s *Store) FindMemoList(ctx context.Context, find *api.MemoFind) ([]*api.Me
func
(
s
*
Store
)
FindMemo
(
ctx
context
.
Context
,
find
*
api
.
MemoFind
)
(
*
api
.
Memo
,
error
)
{
if
find
.
ID
!=
nil
{
memoRaw
:=
&
memoRaw
{}
has
,
err
:=
s
.
cache
.
FindCache
(
api
.
MemoCache
,
*
find
.
ID
,
memoRaw
)
has
,
err
:=
s
.
cache
.
FindCache
(
MemoCache
,
*
find
.
ID
,
memoRaw
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -199,7 +199,7 @@ func (s *Store) FindMemo(ctx context.Context, find *api.MemoFind) (*api.Memo, er
}
memoRaw
:=
list
[
0
]
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
MemoCache
,
memoRaw
.
ID
,
memoRaw
);
err
!=
nil
{
if
err
:=
s
.
cache
.
UpsertCache
(
MemoCache
,
memoRaw
.
ID
,
memoRaw
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -229,7 +229,7 @@ func (s *Store) DeleteMemo(ctx context.Context, delete *api.MemoDelete) error {
return
FormatError
(
err
)
}
s
.
cache
.
DeleteCache
(
api
.
MemoCache
,
delete
.
ID
)
s
.
cache
.
DeleteCache
(
MemoCache
,
delete
.
ID
)
return
nil
}
...
...
store/resource.go
View file @
f74d1b7b
...
...
@@ -97,10 +97,6 @@ func (s *Store) CreateResource(ctx context.Context, create *api.ResourceCreate)
return
nil
,
FormatError
(
err
)
}
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
ResourceCache
,
resourceRaw
.
ID
,
resourceRaw
);
err
!=
nil
{
return
nil
,
err
}
resource
:=
resourceRaw
.
toResource
()
return
resource
,
nil
...
...
@@ -127,17 +123,6 @@ func (s *Store) FindResourceList(ctx context.Context, find *api.ResourceFind) ([
}
func
(
s
*
Store
)
FindResource
(
ctx
context
.
Context
,
find
*
api
.
ResourceFind
)
(
*
api
.
Resource
,
error
)
{
if
find
.
ID
!=
nil
{
resourceRaw
:=
&
resourceRaw
{}
has
,
err
:=
s
.
cache
.
FindCache
(
api
.
ResourceCache
,
*
find
.
ID
,
resourceRaw
)
if
err
!=
nil
{
return
nil
,
err
}
if
has
{
return
resourceRaw
.
toResource
(),
nil
}
}
tx
,
err
:=
s
.
db
.
BeginTx
(
ctx
,
nil
)
if
err
!=
nil
{
return
nil
,
FormatError
(
err
)
...
...
@@ -154,11 +139,6 @@ func (s *Store) FindResource(ctx context.Context, find *api.ResourceFind) (*api.
}
resourceRaw
:=
list
[
0
]
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
ResourceCache
,
resourceRaw
.
ID
,
resourceRaw
);
err
!=
nil
{
return
nil
,
err
}
resource
:=
resourceRaw
.
toResource
()
return
resource
,
nil
...
...
@@ -182,8 +162,6 @@ func (s *Store) DeleteResource(ctx context.Context, delete *api.ResourceDelete)
return
FormatError
(
err
)
}
s
.
cache
.
DeleteCache
(
api
.
ResourceCache
,
delete
.
ID
)
return
nil
}
...
...
@@ -203,10 +181,6 @@ func (s *Store) PatchResource(ctx context.Context, patch *api.ResourcePatch) (*a
return
nil
,
FormatError
(
err
)
}
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
ResourceCache
,
resourceRaw
.
ID
,
resourceRaw
);
err
!=
nil
{
return
nil
,
err
}
resource
:=
resourceRaw
.
toResource
()
return
resource
,
nil
...
...
store/shortcut.go
View file @
f74d1b7b
...
...
@@ -56,7 +56,7 @@ func (s *Store) CreateShortcut(ctx context.Context, create *api.ShortcutCreate)
return
nil
,
FormatError
(
err
)
}
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
ShortcutCache
,
shortcutRaw
.
ID
,
shortcutRaw
);
err
!=
nil
{
if
err
:=
s
.
cache
.
UpsertCache
(
ShortcutCache
,
shortcutRaw
.
ID
,
shortcutRaw
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -81,7 +81,7 @@ func (s *Store) PatchShortcut(ctx context.Context, patch *api.ShortcutPatch) (*a
return
nil
,
FormatError
(
err
)
}
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
ShortcutCache
,
shortcutRaw
.
ID
,
shortcutRaw
);
err
!=
nil
{
if
err
:=
s
.
cache
.
UpsertCache
(
ShortcutCache
,
shortcutRaw
.
ID
,
shortcutRaw
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -113,7 +113,7 @@ func (s *Store) FindShortcutList(ctx context.Context, find *api.ShortcutFind) ([
func
(
s
*
Store
)
FindShortcut
(
ctx
context
.
Context
,
find
*
api
.
ShortcutFind
)
(
*
api
.
Shortcut
,
error
)
{
if
find
.
ID
!=
nil
{
shortcutRaw
:=
&
shortcutRaw
{}
has
,
err
:=
s
.
cache
.
FindCache
(
api
.
ShortcutCache
,
*
find
.
ID
,
shortcutRaw
)
has
,
err
:=
s
.
cache
.
FindCache
(
ShortcutCache
,
*
find
.
ID
,
shortcutRaw
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -139,7 +139,7 @@ func (s *Store) FindShortcut(ctx context.Context, find *api.ShortcutFind) (*api.
shortcutRaw
:=
list
[
0
]
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
ShortcutCache
,
shortcutRaw
.
ID
,
shortcutRaw
);
err
!=
nil
{
if
err
:=
s
.
cache
.
UpsertCache
(
ShortcutCache
,
shortcutRaw
.
ID
,
shortcutRaw
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -164,7 +164,7 @@ func (s *Store) DeleteShortcut(ctx context.Context, delete *api.ShortcutDelete)
return
FormatError
(
err
)
}
s
.
cache
.
DeleteCache
(
api
.
ShortcutCache
,
*
delete
.
ID
)
s
.
cache
.
DeleteCache
(
ShortcutCache
,
*
delete
.
ID
)
return
nil
}
...
...
store/store.go
View file @
f74d1b7b
...
...
@@ -4,7 +4,6 @@ import (
"context"
"database/sql"
"github.com/usememos/memos/api"
"github.com/usememos/memos/server/profile"
)
...
...
@@ -12,7 +11,7 @@ import (
type
Store
struct
{
db
*
sql
.
DB
profile
*
profile
.
Profile
cache
api
.
CacheService
cache
*
CacheService
}
// New creates a new instance of Store.
...
...
store/user.go
View file @
f74d1b7b
...
...
@@ -78,7 +78,7 @@ func (s *Store) CreateUser(ctx context.Context, create *api.UserCreate) (*api.Us
return
nil
,
FormatError
(
err
)
}
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
UserCache
,
userRaw
.
ID
,
userRaw
);
err
!=
nil
{
if
err
:=
s
.
cache
.
UpsertCache
(
UserCache
,
userRaw
.
ID
,
userRaw
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -103,7 +103,7 @@ func (s *Store) PatchUser(ctx context.Context, patch *api.UserPatch) (*api.User,
return
nil
,
FormatError
(
err
)
}
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
UserCache
,
userRaw
.
ID
,
userRaw
);
err
!=
nil
{
if
err
:=
s
.
cache
.
UpsertCache
(
UserCache
,
userRaw
.
ID
,
userRaw
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -135,7 +135,7 @@ func (s *Store) FindUserList(ctx context.Context, find *api.UserFind) ([]*api.Us
func
(
s
*
Store
)
FindUser
(
ctx
context
.
Context
,
find
*
api
.
UserFind
)
(
*
api
.
User
,
error
)
{
if
find
.
ID
!=
nil
{
userRaw
:=
&
userRaw
{}
has
,
err
:=
s
.
cache
.
FindCache
(
api
.
UserCache
,
*
find
.
ID
,
userRaw
)
has
,
err
:=
s
.
cache
.
FindCache
(
UserCache
,
*
find
.
ID
,
userRaw
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -161,7 +161,7 @@ func (s *Store) FindUser(ctx context.Context, find *api.UserFind) (*api.User, er
userRaw
:=
list
[
0
]
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
UserCache
,
userRaw
.
ID
,
userRaw
);
err
!=
nil
{
if
err
:=
s
.
cache
.
UpsertCache
(
UserCache
,
userRaw
.
ID
,
userRaw
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -188,7 +188,7 @@ func (s *Store) DeleteUser(ctx context.Context, delete *api.UserDelete) error {
return
err
}
s
.
cache
.
DeleteCache
(
api
.
UserCache
,
delete
.
ID
)
s
.
cache
.
DeleteCache
(
UserCache
,
delete
.
ID
)
return
nil
}
...
...
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