diff options
author | Tamal Saha <tamal@appscode.com> | 2019-08-23 09:40:30 -0700 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-08-23 12:40:29 -0400 |
commit | 171b3598778a1ecd0a921c71ed6755bfef68f7f0 (patch) | |
tree | 02857629ef9e8e26ee0ee559153f803f77b588b7 /vendor/github.com/bradfitz/gomemcache | |
parent | ca6fb004ac50fc924861112403895d637c6a2d1d (diff) | |
download | gitea-171b3598778a1ecd0a921c71ed6755bfef68f7f0.tar.gz gitea-171b3598778a1ecd0a921c71ed6755bfef68f7f0.zip |
Use gitea forked macaron (#7933)
Signed-off-by: Tamal Saha <tamal@appscode.com>
Diffstat (limited to 'vendor/github.com/bradfitz/gomemcache')
-rw-r--r-- | vendor/github.com/bradfitz/gomemcache/memcache/memcache.go | 47 | ||||
-rw-r--r-- | vendor/github.com/bradfitz/gomemcache/memcache/selector.go | 19 |
2 files changed, 51 insertions, 15 deletions
diff --git a/vendor/github.com/bradfitz/gomemcache/memcache/memcache.go b/vendor/github.com/bradfitz/gomemcache/memcache/memcache.go index 7b5442d735..25e88ca261 100644 --- a/vendor/github.com/bradfitz/gomemcache/memcache/memcache.go +++ b/vendor/github.com/bradfitz/gomemcache/memcache/memcache.go @@ -23,7 +23,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net" "strconv" @@ -33,7 +32,7 @@ import ( ) // Similar to: -// http://code.google.com/appengine/docs/go/memcache/reference.html +// https://godoc.org/google.golang.org/appengine/memcache var ( // ErrCacheMiss means that a Get failed because the item wasn't present. @@ -56,7 +55,7 @@ var ( ErrNoStats = errors.New("memcache: no statistics available") // ErrMalformedKey is returned when an invalid key is used. - // Keys must be at maximum 250 bytes long, ASCII, and not + // Keys must be at maximum 250 bytes long and not // contain whitespace or control characters. ErrMalformedKey = errors.New("malformed: key is too long or contains invalid characters") @@ -64,14 +63,17 @@ var ( ErrNoServers = errors.New("memcache: no servers configured or available") ) -// DefaultTimeout is the default socket read/write timeout. -const DefaultTimeout = 100 * time.Millisecond - const ( - buffered = 8 // arbitrary buffered channel size, for readability - maxIdleConnsPerAddr = 2 // TODO(bradfitz): make this configurable? + // DefaultTimeout is the default socket read/write timeout. + DefaultTimeout = 100 * time.Millisecond + + // DefaultMaxIdleConns is the default maximum number of idle connections + // kept for any single address. + DefaultMaxIdleConns = 2 ) +const buffered = 8 // arbitrary buffered channel size, for readability + // resumableError returns true if err is only a protocol-level cache error. // This is used to determine whether or not a server connection should // be re-used or not. If an error occurs, by default we don't reuse the @@ -89,7 +91,7 @@ func legalKey(key string) bool { return false } for i := 0; i < len(key); i++ { - if key[i] <= ' ' || key[i] > 0x7e { + if key[i] <= ' ' || key[i] == 0x7f { return false } } @@ -133,6 +135,14 @@ type Client struct { // If zero, DefaultTimeout is used. Timeout time.Duration + // MaxIdleConns specifies the maximum number of idle connections that will + // be maintained per address. If less than one, DefaultMaxIdleConns will be + // used. + // + // Consider your expected traffic rates and latency carefully. This should + // be set to a number higher than your peak parallel requests. + MaxIdleConns int + selector ServerSelector lk sync.Mutex @@ -196,7 +206,7 @@ func (c *Client) putFreeConn(addr net.Addr, cn *conn) { c.freeconn = make(map[string][]*conn) } freelist := c.freeconn[addr.String()] - if len(freelist) >= maxIdleConnsPerAddr { + if len(freelist) >= c.maxIdleConns() { cn.nc.Close() return } @@ -225,6 +235,13 @@ func (c *Client) netTimeout() time.Duration { return DefaultTimeout } +func (c *Client) maxIdleConns() int { + if c.MaxIdleConns > 0 { + return c.MaxIdleConns + } + return DefaultMaxIdleConns +} + // ConnectTimeoutError is the error type used when it takes // too long to connect to the desired host. This level of // detail can generally be ignored. @@ -308,8 +325,9 @@ func (c *Client) Get(key string) (item *Item, err error) { // Touch updates the expiry for the given key. The seconds parameter is either // a Unix timestamp or, if seconds is less than 1 month, the number of seconds -// into the future at which time the item will expire. ErrCacheMiss is returned if the -// key is not in the cache. The key must be at most 250 bytes in length. +// into the future at which time the item will expire. Zero means the item has +// no expiration time. ErrCacheMiss is returned if the key is not in the cache. +// The key must be at most 250 bytes in length. func (c *Client) Touch(key string, seconds int32) (err error) { return c.withKeyAddr(key, func(addr net.Addr) error { return c.touchFromAddr(addr, []string{key}, seconds) @@ -463,11 +481,14 @@ func parseGetResponse(r *bufio.Reader, cb func(*Item)) error { if err != nil { return err } - it.Value, err = ioutil.ReadAll(io.LimitReader(r, int64(size)+2)) + it.Value = make([]byte, size+2) + _, err = io.ReadFull(r, it.Value) if err != nil { + it.Value = nil return err } if !bytes.HasSuffix(it.Value, crlf) { + it.Value = nil return fmt.Errorf("memcache: corrupt get result read") } it.Value = it.Value[:size] diff --git a/vendor/github.com/bradfitz/gomemcache/memcache/selector.go b/vendor/github.com/bradfitz/gomemcache/memcache/selector.go index 10b04d349f..89ad81e0d8 100644 --- a/vendor/github.com/bradfitz/gomemcache/memcache/selector.go +++ b/vendor/github.com/bradfitz/gomemcache/memcache/selector.go @@ -41,6 +41,21 @@ type ServerList struct { addrs []net.Addr } +// staticAddr caches the Network() and String() values from any net.Addr. +type staticAddr struct { + ntw, str string +} + +func newStaticAddr(a net.Addr) net.Addr { + return &staticAddr{ + ntw: a.Network(), + str: a.String(), + } +} + +func (s *staticAddr) Network() string { return s.ntw } +func (s *staticAddr) String() string { return s.str } + // SetServers changes a ServerList's set of servers at runtime and is // safe for concurrent use by multiple goroutines. // @@ -58,13 +73,13 @@ func (ss *ServerList) SetServers(servers ...string) error { if err != nil { return err } - naddr[i] = addr + naddr[i] = newStaticAddr(addr) } else { tcpaddr, err := net.ResolveTCPAddr("tcp", server) if err != nil { return err } - naddr[i] = tcpaddr + naddr[i] = newStaticAddr(tcpaddr) } } |