1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 00:50:55 +00:00

Merge pull request #4237 from flycash/rft/cache-decup

Decouple web module from cache module
This commit is contained in:
Ming Deng 2020-10-04 19:01:31 +08:00 committed by GitHub
commit b89d9511ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -68,7 +68,6 @@ import (
"github.com/astaxie/beego/pkg/infrastructure/logs" "github.com/astaxie/beego/pkg/infrastructure/logs"
"github.com/astaxie/beego/pkg/client/cache"
"github.com/astaxie/beego/pkg/infrastructure/utils" "github.com/astaxie/beego/pkg/infrastructure/utils"
"github.com/astaxie/beego/pkg/server/web" "github.com/astaxie/beego/pkg/server/web"
"github.com/astaxie/beego/pkg/server/web/context" "github.com/astaxie/beego/pkg/server/web/context"
@ -91,7 +90,7 @@ const (
// Captcha struct // Captcha struct
type Captcha struct { type Captcha struct {
// beego cache store // beego cache store
store cache.Cache store Storage
// url prefix for captcha image // url prefix for captcha image
URLPrefix string URLPrefix string
@ -232,7 +231,7 @@ func (c *Captcha) Verify(id string, challenge string) (success bool) {
} }
// NewCaptcha create a new captcha.Captcha // NewCaptcha create a new captcha.Captcha
func NewCaptcha(urlPrefix string, store cache.Cache) *Captcha { func NewCaptcha(urlPrefix string, store Storage) *Captcha {
cpt := &Captcha{} cpt := &Captcha{}
cpt.store = store cpt.store = store
cpt.FieldIDName = fieldIDName cpt.FieldIDName = fieldIDName
@ -258,7 +257,7 @@ func NewCaptcha(urlPrefix string, store cache.Cache) *Captcha {
// NewWithFilter create a new captcha.Captcha and auto AddFilter for serve captacha image // NewWithFilter create a new captcha.Captcha and auto AddFilter for serve captacha image
// and add a template func for output html // and add a template func for output html
func NewWithFilter(urlPrefix string, store cache.Cache) *Captcha { func NewWithFilter(urlPrefix string, store Storage) *Captcha {
cpt := NewCaptcha(urlPrefix, store) cpt := NewCaptcha(urlPrefix, store)
// create filter for serve captcha image // create filter for serve captcha image
@ -269,3 +268,12 @@ func NewWithFilter(urlPrefix string, store cache.Cache) *Captcha {
return cpt return cpt
} }
type Storage interface {
// Get a cached value by key.
Get(key string) interface{}
// Set a cached value with key and expire time.
Put(key string, val interface{}, timeout time.Duration) error
// Delete cached value by key.
Delete(key string) error
}