GoFrame 緩存管理-接口化設(shè)計(jì)

2022-04-01 10:16 更新

緩存組件采用了接口化設(shè)計(jì),提供了?Adapter?接口,任何實(shí)現(xiàn)了?Adapter?接口的對(duì)象均可注冊(cè)到緩存管理對(duì)象中,使得開發(fā)者可以對(duì)緩存管理對(duì)象進(jìn)行靈活的自定義實(shí)現(xiàn)和擴(kuò)展。

接口定義

?Adapter?接口定義如下:

https://pkg.go.dev/github.com/gogf/gf/v2/os/gcache#Adapter

注冊(cè)接口實(shí)現(xiàn)

通過該方法將實(shí)現(xiàn)的?adapter?應(yīng)用到對(duì)應(yīng)的?Cache?對(duì)象上:

// 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)

獲取接口實(shí)現(xiàn)

通過該方法獲取當(dāng)前注冊(cè)的?adapter?接口實(shí)現(xiàn)對(duì)象上:

// GetAdapter returns the adapter that is set in current Cache.
func (c *Cache) GetAdapter() Adapter


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)