Skip to main content
Version: 2.8.x(Latest)

The cache component adopts an interface design, providing the Adapter interface. Any object implementing the Adapter interface can be registered into the cache management object, allowing developers to flexibly customize and extend the cache management object.

Interface Definition

The Adapter interface is defined as follows:

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

Registering Interface Implementation

This method applies the implemented adapter to the corresponding Cache object:

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

For specific examples, please refer to the Caching - Redis section.

Obtaining Interface Implementation

This method retrieves the currently registered adapter interface implementation object:

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

For specific examples, please refer to the Caching - Redis section.