1 Star 0 Fork 0

小于的个人工具集/xcache

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

xcache

介绍

缓存仓库,默认使用内存缓存,而若使用其他缓存请先进行声明

支持的方法

PS: .xxx 为xcache.xxx的简写,作用为避免部分场景下使用别名导入的形式直接

方法 作用
CacheInterfaceExport{} 内存形缓存结构体,实现有Get和Set两个方法,基于此结构体内的缓存锁,实现有并发锁定
.SetCacheTime(t time.Duration) 设置默认缓存时长
.SetCache(c CacheInterface) 设置缓存的存储方式【接口形式】
.Exists(name string) 判断缓存值是否存在,此处是根据缓存是否为空来判断是否存在的,即内部实现为:.Get(name) == ""
.Get(name string) 获取缓存信息
.GetString(name string) 获取缓存信息,等同于.Get
.GetStruct(key string, val any) 读取结构体,val传入的值需要为结构体指针,内部为 json.Unmarshal 解析
.SetExt(key, val string, t time.Duration) 设置缓存值
.SetGroup(n, key, val string, t time.Duration) 以分组的形式设置缓存值
.Set(key, val string) 设置缓存值,其内实现逻辑为:.SetExt(key, val, time.Second*60)
.SetNumber(key string, val any) 设置数字类型的缓存值,默认时长1分钟
.SetStruct(key string, val any) 设置结构体类型的缓存值,默认时长1分钟
.SetStructExt(key string, val any, t time.Duration) 设置指定时长的缓存值
.SetStructGroup(g, key string, val any) 设置结构体缓存【带分组】
.SetStruct(key string, val any) 设置结构体缓存【不带分组】
.Clear() 清空全部缓存【此处清空group中存在的所有缓存,而非清除所有】
.Remove(name string) 清除单个缓存
.ClearGroup(name string) 清除某组缓存

使用

// 声明缓存结构体
type cache struct{}

// 实现GET方法
func (c *cache) Get(name string) string {
    // 实现逻辑
    return ""
}

// 实现SET方法
func (c *cache) Set(name string, val string, t time.Duration) {

}
// 设置该缓存到本依赖项中
xcache.SetCache(&cache{})
MIT License Copyright (c) 2023 xiaoyutab Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

缓存仓库 展开 收起
README
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/xgotool/xcache.git
git@gitee.com:xgotool/xcache.git
xgotool
xcache
xcache
master

搜索帮助