Versions Compared
compared with
Key
- This line was added.
- This line was removed.
- Formatting was changed.
...
缓存组件采用了接口化设计,提供了Adapter
...
接口,任何实现了Adapter
...
gcache.Cache
对象结构定义如下:
接口的对象均可注册到缓存管理对象中,使得开发者可以对缓存管理对象进行灵活的自定义实现和扩展。
接口定义
...
Adapter
接口定义如下:
...
...
dev/github.com/gogf/gf/v2/os/gcache#Adapter
注册接口实现
通过该方法将实现的adapter
应用到对应的Cache
对象上:
Code Block | ||
---|---|---|
| ||
// |
...
SetAdapter |
...
changes the adapter for |
...
this cache.
// Be very note that, this setting function is not concurrent-safe, which means you should not call
// this setting function concurrently in multiple goroutines.
func (c *Cache) SetAdapter(adapter Adapter) |
具体示例请参考 缓存管理-Redis缓存 章节。
获取接口实现
通过该方法获取当前注册的adapter
接口实现对象上:
Code Block | ||
---|---|---|
| ||
// GetAdapter returns the adapter that is set in current Cache |
...
适配器的注册方法:
...
.
func (c *Cache) |
...
GetAdapter( |
...
) Adapter |
...
Panel | ||
---|---|---|
| ||
|