-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1262 from longguikeji/release-2.5.12
Release 2.5.12
- Loading branch information
Showing
22 changed files
with
320 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from arkid.core.event import Event, dispatch_event,CACHE_GET,CACHE_SET | ||
from django.core.cache import cache | ||
|
||
def get(tenant,key,**kwargs): | ||
rs = dispatch_event(Event(tag=CACHE_GET, tenant=tenant,data={"key":key,**kwargs})) | ||
for useless,(response,useless) in rs: | ||
if not response: | ||
continue | ||
return response | ||
|
||
return cache.get(key) | ||
|
||
def set(tenant,key,value,**kwargs): | ||
rs = dispatch_event(Event(tag=CACHE_SET, tenant=tenant,data={"key":key,"value":value,**kwargs})) | ||
for useless,(response,useless) in rs: | ||
if not response: | ||
continue | ||
return response | ||
|
||
return cache.set(key,value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
from abc import abstractmethod | ||
from typing import Optional | ||
import uuid | ||
from arkid.common.logger import logger | ||
from arkid.core.extension import Extension | ||
from arkid.core.translation import gettext_default as _ | ||
from arkid.core.event import CACHE_SET,CACHE_GET | ||
|
||
|
||
class CacheExtension(Extension): | ||
|
||
TYPE = "cache" | ||
|
||
@property | ||
def type(self): | ||
return CacheExtension.TYPE | ||
|
||
def load(self): | ||
super().load() | ||
self.listen_event(CACHE_GET, self.event_cache_get) | ||
self.listen_event(CACHE_SET, self.event_cache_set) | ||
|
||
def event_cache_get(self, event, **kwargs): | ||
try: | ||
return self.get( | ||
event.tenant, | ||
**event.data | ||
) | ||
except Exception as err: | ||
logger.error(err) | ||
|
||
def event_cache_set(self,event,**kwargs): | ||
try: | ||
return self.set( | ||
tenant=event.tenant, | ||
**event.data | ||
) | ||
except Exception as err: | ||
logger.error(err) | ||
|
||
@abstractmethod | ||
def get(self, tenant, key: str, **kwargs): | ||
"""读取 | ||
Args: | ||
tenant:租户 | ||
key: 存储名称 | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
def set(self, tenant, key: str, value:any, **kwargs)-> bool: | ||
"""存储 | ||
Args: | ||
key (str): 存储名称 | ||
tenant (Tenant): 租户 | ||
value:值 | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## 功能介绍 | ||
|
||
消息中间件插件用于平台引入消息中间件(如Artemis,kafka等)与第三方系统进行消息通信(如通知数据) | ||
|
||
## 实现思路 | ||
开发者在开发消息中间件插件时,仅需继承消息中间件插件基类并完成数据写入过程,平台已提供消息存储模型(可扩展),且在基类中提供消息存储方法: | ||
|
||
## 基类定义 | ||
|
||
::: arkid.core.extension.message.MessageExtension | ||
rendering: | ||
show_source: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
## 功能介绍 | ||
|
||
缓存插件为平台提供缓存功能,即开发者在需要缓存支持时通过缓存插件引入如redis等缓存数据库并使用它们完成缓存事务。 | ||
|
||
## 实现思路 | ||
开发者在开发缓存插件时,仅需继承缓存插件基类并重载get/set函数即可,处理流程如下: | ||
|
||
```mermaid | ||
sequenceDiagram | ||
participant C as 平台核心 | ||
participant B as 缓存插件 | ||
C->>B: 加载插件 | ||
B->>C: 注册监听缓存事件 | ||
rect rgb(191, 223, 255) | ||
C->>B: 发出设置/获取缓存事件(CACHE_SET/CACHE_GET) | ||
B->>C: 响应事件并根据自身配置操作缓存,返回结果(成功/失败,获取数据) | ||
end | ||
``` | ||
|
||
## 缓存使用方法 | ||
示例如下: | ||
``` python | ||
|
||
from arkid.common import cache #引入平台缓存 | ||
|
||
cache.set(tenant,key,value,expired) # 参数依次为:租户,缓存KEY, 缓存VALUE, 过期时间 | ||
|
||
cache.get(tenant,key) #参数依次为:租户,缓存KEY | ||
|
||
``` | ||
|
||
## 抽象函数 | ||
|
||
* [get](#arkid.core.extension.cache.CacheExtension.get) | ||
* [set](#arkid.core.extension.cache.CacheExtension.set) | ||
|
||
## 基类定义 | ||
|
||
::: arkid.core.extension.cache.CacheExtension | ||
rendering: | ||
show_source: true |
Oops, something went wrong.