Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
Koishi Plugin Cache Memcached
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
3rdeye
Koishi Plugin Cache Memcached
Commits
caa1a891
Commit
caa1a891
authored
Oct 19, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
catchup for del method
parent
6f414b26
Pipeline
#6337
passed with stages
in 37 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
12 deletions
+22
-12
package.json
package.json
+1
-1
src/plugin.ts
src/plugin.ts
+21
-11
No files found.
package.json
View file @
caa1a891
{
"name"
:
"koishi-plugin-cache-memcached"
,
"version"
:
"1.0.
0
"
,
"version"
:
"1.0.
1
"
,
"description"
:
"Memcached cache support for Koishi.js"
,
"main"
:
"dist/index.js"
,
"types"
:
"dist/index.d.ts"
,
...
...
src/plugin.ts
View file @
caa1a891
import
'
source-map-support/register
'
;
import
{
Context
,
Schema
,
Cache
,
Logger
}
from
'
koishi
'
;
import
{
Context
,
Schema
,
Cache
,
Logger
,
isNullable
}
from
'
koishi
'
;
import
{
MemcachedCachePluginConfig
,
MemcachedCachePluginConfigLike
,
...
...
@@ -92,7 +92,7 @@ export class MemcachedCache extends Cache {
return
;
}
const
decodedValue
=
await
this
.
decode
(
value
);
this
.
logger
.
info
(
`
${
actualKey
}
=>
${
JSON
.
stringify
(
decodedValue
)}
`
);
//
this.logger.info(`${actualKey} => ${JSON.stringify(decodedValue)}`);
return
decodedValue
;
}
catch
(
e
)
{
this
.
logger
.
error
(
`Get key of
${
actualKey
}
errored:
${
e
.
toString
()}
`
);
...
...
@@ -109,25 +109,35 @@ export class MemcachedCache extends Cache {
if
(
!
this
.
table
(
table
))
{
return
;
}
if
(
isNullable
(
value
))
{
return
this
.
del
(
table
,
key
);
}
const
actualKey
=
await
this
.
getKey
(
table
,
key
);
const
age
=
maxAge
||
this
.
getAgeOfTable
(
table
);
try
{
let
result
:
boolean
;
if
(
value
==
null
)
{
result
=
await
this
.
mem
.
delete
(
actualKey
);
}
else
{
result
=
await
this
.
mem
.
set
(
actualKey
,
await
this
.
encode
(
value
),
{
const
result
=
await
this
.
mem
.
set
(
actualKey
,
await
this
.
encode
(
value
),
{
expires
:
age
,
});
}
if
(
!
result
)
{
this
.
logger
.
error
(
`Set key of
${
actualKey
}
failed.`
);
this
.
logger
.
warn
(
`Set key of
${
actualKey
}
failed.`
);
}
}
catch
(
e
)
{
this
.
logger
.
error
(
`Set key of
${
actualKey
}
errored:
${
e
.
toString
()}
`
);
}
}
async
del
(
table
:
keyof
Cache
.
Tables
,
key
:
string
)
{
const
actualKey
=
await
this
.
getKey
(
table
,
key
);
try
{
const
result
=
await
this
.
mem
.
delete
(
actualKey
);
if
(
!
result
)
{
this
.
logger
.
warn
(
`Delete key
${
actualKey
}
failed.`
);
}
}
catch
(
e
)
{
this
.
logger
.
error
(
`Delete key
${
actualKey
}
errored:
${
e
.
toString
()}
`
);
}
}
async
clear
(
table
:
keyof
Cache
.
Tables
)
{
await
this
.
resetVersion
(
table
);
return
;
...
...
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