Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

gcache模块采用了适配器设计模式,提供了缓存组件采用了适配器设计模式,提供了Adapter适配器接口,任何实现了Adapter接口的对象均可注册到缓存管理对象中,使得开发者可以对缓存管理对象进行灵活的扩展。

接口定义

Adapter接口定义如下:

https://godoc.org/github.com/gogf/gf/os/gcache#Adapter

接口注册

适配器的注册方法,将实现的adapter应用到对应的Cache对象上:

Code Block
languagego
// 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缓存 章节。






Panel
titleContent Menu

Table of Contents