godoc.txt 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. PACKAGE
  2. package memcache
  3. import "github.com/bradfitz/gomemcache"
  4. Package memcache provides a client for the memcached cache server.
  5. CONSTANTS
  6. const DefaultTimeoutNanos = 100e6 // 100 ms
  7. DefaultTimeoutNanos is the default socket read/write timeout, in nanoseconds.
  8. VARIABLES
  9. var (
  10. // ErrCacheMiss means that a Get failed because the item wasn't present.
  11. ErrCacheMiss = os.NewError("memcache: cache miss")
  12. // ErrCASConflict means that a CompareAndSwap call failed due to the
  13. // cached value being modified between the Get and the CompareAndSwap.
  14. // If the cached value was simply evicted rather than replaced,
  15. // ErrNotStored will be returned instead.
  16. ErrCASConflict = os.NewError("memcache: compare-and-swap conflict")
  17. // ErrNotStored means that a conditional write operation (i.e. Add or
  18. // CompareAndSwap) failed because the condition was not satisfied.
  19. ErrNotStored = os.NewError("memcache: item not stored")
  20. // ErrServer means that a server error occurred.
  21. ErrServerError = os.NewError("memcache: server error")
  22. // ErrNoStats means that no statistics were available.
  23. ErrNoStats = os.NewError("memcache: no statistics available")
  24. // ErrMalformedKey is returned when an invalid key is used.
  25. // Keys must be at maximum 250 bytes long, ASCII, and not
  26. // contain whitespace or control characters.
  27. ErrMalformedKey = os.NewError("malformed: key is too long or contains invalid characters")
  28. // ErrNoServers is returned when no servers are configured or available.
  29. ErrNoServers = os.NewError("memcache: no servers configured or available")
  30. )
  31. TYPES
  32. type Client struct {
  33. // TimeoutNanos specifies the socket read/write timeout.
  34. // If zero, DefaultTimeoutNanos is used.
  35. TimeoutNanos int64
  36. // contains filtered or unexported fields
  37. }
  38. Client is a memcache client.
  39. It is safe for unlocked use by multiple concurrent goroutines.
  40. func New(server ...string) *Client
  41. New returns a memcache client using the provided server(s)
  42. with equal weight. If a server is listed multiple times,
  43. it gets a proportional amount of weight.
  44. func NewFromSelector(ss ServerSelector) *Client
  45. NewFromSelector returns a new Client using the provided ServerSelector.
  46. func (c *Client) Add(item *Item) os.Error
  47. Add writes the given item, if no value already exists for its
  48. key. ErrNotStored is returned if that condition is not met.
  49. func (c *Client) CompareAndSwap(item *Item) os.Error
  50. CompareAndSwap writes the given item that was previously returned
  51. by Get, if the value was neither modified or evicted between the
  52. Get and the CompareAndSwap calls. The item's Key should not change
  53. between calls but all other item fields may differ. ErrCASConflict
  54. is returned if the value was modified in between the
  55. calls. ErrNotStored is returned if the value was evicted in between
  56. the calls.
  57. func (c *Client) Delete(key string) os.Error
  58. Delete deletes the item with the provided key. The error ErrCacheMiss is
  59. returned if the item didn't already exist in the cache.
  60. func (c *Client) DeleteLock(key string, seconds int) os.Error
  61. Delete deletes the item with the provided key, also instructing the
  62. server to not permit an "add" or "replace" commands to work on the
  63. key for the given duration (in seconds). The error ErrCacheMiss is
  64. returned if the item didn't already exist in the cache.
  65. func (c *Client) Get(key string) (item *Item, err os.Error)
  66. Get gets the item for the given key. ErrCacheMiss is returned for a
  67. memcache cache miss. The key must be at most 250 bytes in length.
  68. func (c *Client) GetMulti(keys []string) (map[string]*Item, os.Error)
  69. GetMulti is a batch version of Get. The returned map from keys to
  70. items may have fewer elements than the input slice, due to memcache
  71. cache misses. Each key must be at most 250 bytes in length.
  72. If no error is returned, the returned map will also be non-nil.
  73. func (c *Client) Set(item *Item) os.Error
  74. Set writes the given item, unconditionally.
  75. type Item struct {
  76. // Key is the Item's key (250 bytes maximum).
  77. Key string
  78. // Value is the Item's value.
  79. Value []byte
  80. // Object is the Item's value for use with a Codec.
  81. Object interface{}
  82. // Flags are server-opaque flags whose semantics are entirely up to the
  83. // App Engine app.
  84. Flags uint32
  85. // Expiration is the cache expiration time, in seconds: either a relative
  86. // time from now (up to 1 month), or an absolute Unix epoch time.
  87. // Zero means the Item has no expiration time.
  88. Expiration int32
  89. // contains filtered or unexported fields
  90. }
  91. Item is an item to be got or stored in a memcached server.
  92. type ServerList struct {
  93. // contains filtered or unexported fields
  94. }
  95. ServerList is a simple ServerSelector. Its zero value is usable.
  96. func (ss *ServerList) PickServer(key string) (net.Addr, os.Error)
  97. func (ss *ServerList) SetServers(servers ...string) os.Error
  98. SetServers changes a ServerList's set of servers at runtime and is
  99. threadsafe.
  100. Each server is given equal weight. A server is given more weight
  101. if it's listed multiple times.
  102. SetServers returns an error if any of the server names fail to
  103. resolve. No attempt is made to connect to the server. If any error
  104. is returned, no changes are made to the ServerList.
  105. type ServerSelector interface {
  106. // PickServer returns the server address that a given item
  107. // should be shared onto.
  108. PickServer(key string) (net.Addr, os.Error)
  109. }
  110. ServerSelector is the interface that selects a memcache server
  111. as a function of the item's key.
  112. All ServerSelector implementations must be threadsafe.
  113. SUBDIRECTORIES
  114. .git