godoc.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <!--
  2. Copyright 2009 The Go Authors. All rights reserved.
  3. Use of this source code is governed by a BSD-style
  4. license that can be found in the LICENSE file.
  5. -->
  6. <!-- PackageName is printed as title by the top-level template -->
  7. <p><code>import "."</code></p>
  8. <p>
  9. Package memcache provides a client for the memcached cache server.
  10. </p>
  11. <p>
  12. <h4>Package files</h4>
  13. <span style="font-size:90%">
  14. <a href="/">memcache.go</a>
  15. <a href="/">selector.go</a>
  16. </span>
  17. </p>
  18. <h2 id="Constants">Constants</h2>
  19. <p>
  20. DefaultTimeoutNanos is the default socket read/write timeout, in nanoseconds.
  21. </p>
  22. <pre>const DefaultTimeoutNanos = 100e6 <span class="comment">// 100 ms</span>
  23. </pre>
  24. <h2 id="Variables">Variables</h2>
  25. <pre>var (
  26. <span class="comment">// ErrCacheMiss means that a Get failed because the item wasn&#39;t present.</span>
  27. ErrCacheMiss = os.NewError(&#34;memcache: cache miss&#34;)
  28. <span class="comment">// ErrCASConflict means that a CompareAndSwap call failed due to the</span>
  29. <span class="comment">// cached value being modified between the Get and the CompareAndSwap.</span>
  30. <span class="comment">// If the cached value was simply evicted rather than replaced,</span>
  31. <span class="comment">// ErrNotStored will be returned instead.</span>
  32. ErrCASConflict = os.NewError(&#34;memcache: compare-and-swap conflict&#34;)
  33. <span class="comment">// ErrNotStored means that a conditional write operation (i.e. Add or</span>
  34. <span class="comment">// CompareAndSwap) failed because the condition was not satisfied.</span>
  35. ErrNotStored = os.NewError(&#34;memcache: item not stored&#34;)
  36. <span class="comment">// ErrServer means that a server error occurred.</span>
  37. ErrServerError = os.NewError(&#34;memcache: server error&#34;)
  38. <span class="comment">// ErrNoStats means that no statistics were available.</span>
  39. ErrNoStats = os.NewError(&#34;memcache: no statistics available&#34;)
  40. <span class="comment">// ErrMalformedKey is returned when an invalid key is used.</span>
  41. <span class="comment">// Keys must be at maximum 250 bytes long, ASCII, and not</span>
  42. <span class="comment">// contain whitespace or control characters.</span>
  43. ErrMalformedKey = os.NewError(&#34;malformed: key is too long or contains invalid characters&#34;)
  44. <span class="comment">// ErrNoServers is returned when no servers are configured or available.</span>
  45. ErrNoServers = os.NewError(&#34;memcache: no servers configured or available&#34;)
  46. )</pre>
  47. <h2 id="Client">type <a href="/?s=3851:4072#L115">Client</a></h2>
  48. <p>
  49. Client is a memcache client.
  50. It is safe for unlocked use by multiple concurrent goroutines.
  51. </p>
  52. <p><pre>type Client struct {
  53. <span class="comment">// TimeoutNanos specifies the socket read/write timeout.</span>
  54. <span class="comment">// If zero, DefaultTimeoutNanos is used.</span>
  55. TimeoutNanos int64
  56. <span class="comment">// contains filtered or unexported fields</span>
  57. }</pre></p>
  58. <h3 id="Client.New">func <a href="/?s=3478:3512#L102">New</a></h3>
  59. <p><code>func New(server ...string) *Client</code></p>
  60. <p>
  61. New returns a memcache client using the provided server(s)
  62. with equal weight. If a server is listed multiple times,
  63. it gets a proportional amount of weight.
  64. </p>
  65. <h3 id="Client.NewFromSelector">func <a href="/?s=3670:3717#L109">NewFromSelector</a></h3>
  66. <p><code>func NewFromSelector(ss ServerSelector) *Client</code></p>
  67. <p>
  68. NewFromSelector returns a new Client using the provided ServerSelector.
  69. </p>
  70. <h3 id="Client.Add">func (*Client) <a href="/?s=10366:10407#L379">Add</a></h3>
  71. <p><code>func (c *Client) Add(item *Item) os.Error</code></p>
  72. <p>
  73. Add writes the given item, if no value already exists for its
  74. key. ErrNotStored is returned if that condition is not met.
  75. </p>
  76. <h3 id="Client.CompareAndSwap">func (*Client) <a href="/?s=10977:11029#L394">CompareAndSwap</a></h3>
  77. <p><code>func (c *Client) CompareAndSwap(item *Item) os.Error</code></p>
  78. <p>
  79. CompareAndSwap writes the given item that was previously returned
  80. by Get, if the value was neither modified or evicted between the
  81. Get and the CompareAndSwap calls. The item&#39;s Key should not change
  82. between calls but all other item fields may differ. ErrCASConflict
  83. is returned if the value was modified in between the
  84. calls. ErrNotStored is returned if the value was evicted in between
  85. the calls.
  86. </p>
  87. <h3 id="Client.Delete">func (*Client) <a href="/?s=13002:13046#L470">Delete</a></h3>
  88. <p><code>func (c *Client) Delete(key string) os.Error</code></p>
  89. <p>
  90. Delete deletes the item with the provided key. The error ErrCacheMiss is
  91. returned if the item didn&#39;t already exist in the cache.
  92. </p>
  93. <h3 id="Client.DeleteLock">func (*Client) <a href="/?s=13351:13412#L478">DeleteLock</a></h3>
  94. <p><code>func (c *Client) DeleteLock(key string, seconds int) os.Error</code></p>
  95. <p>
  96. Delete deletes the item with the provided key, also instructing the
  97. server to not permit an &#34;add&#34; or &#34;replace&#34; commands to work on the
  98. key for the given duration (in seconds). The error ErrCacheMiss is
  99. returned if the item didn&#39;t already exist in the cache.
  100. </p>
  101. <h3 id="Client.Get">func (*Client) <a href="/?s=6852:6911#L242">Get</a></h3>
  102. <p><code>func (c *Client) Get(key string) (item *Item, err os.Error)</code></p>
  103. <p>
  104. Get gets the item for the given key. ErrCacheMiss is returned for a
  105. memcache cache miss. The key must be at most 250 bytes in length.
  106. </p>
  107. <h3 id="Client.GetMulti">func (*Client) <a href="/?s=8411:8480#L297">GetMulti</a></h3>
  108. <p><code>func (c *Client) GetMulti(keys []string) (map[string]*Item, os.Error)</code></p>
  109. <p>
  110. GetMulti is a batch version of Get. The returned map from keys to
  111. items may have fewer elements than the input slice, due to memcache
  112. cache misses. Each key must be at most 250 bytes in length.
  113. If no error is returned, the returned map will also be non-nil.
  114. </p>
  115. <h3 id="Client.Set">func (*Client) <a href="/?s=10045:10086#L369">Set</a></h3>
  116. <p><code>func (c *Client) Set(item *Item) os.Error</code></p>
  117. <p>
  118. Set writes the given item, unconditionally.
  119. </p>
  120. <h2 id="Item">type <a href="/?s=4136:4692#L127">Item</a></h2>
  121. <p>
  122. Item is an item to be got or stored in a memcached server.
  123. </p>
  124. <p><pre>type Item struct {
  125. <span class="comment">// Key is the Item&#39;s key (250 bytes maximum).</span>
  126. Key string
  127. <span class="comment">// Value is the Item&#39;s value.</span>
  128. Value []byte
  129. <span class="comment">// Object is the Item&#39;s value for use with a Codec.</span>
  130. Object interface{}
  131. <span class="comment">// Flags are server-opaque flags whose semantics are entirely up to the</span>
  132. <span class="comment">// App Engine app.</span>
  133. Flags uint32
  134. <span class="comment">// Expiration is the cache expiration time, in seconds: either a relative</span>
  135. <span class="comment">// time from now (up to 1 month), or an absolute Unix epoch time.</span>
  136. <span class="comment">// Zero means the Item has no expiration time.</span>
  137. Expiration int32
  138. <span class="comment">// contains filtered or unexported fields</span>
  139. }</pre></p>
  140. <h2 id="ServerList">type <a href="/?s=1023:1087#L27">ServerList</a></h2>
  141. <p>
  142. ServerList is a simple ServerSelector. Its zero value is usable.
  143. </p>
  144. <p><pre>type ServerList struct {
  145. <span class="comment">// contains filtered or unexported fields</span>
  146. }</pre></p>
  147. <h3 id="ServerList.PickServer">func (*ServerList) <a href="/?s=1793:1858#L57">PickServer</a></h3>
  148. <p><code>func (ss *ServerList) PickServer(key string) (net.Addr, os.Error)</code></p>
  149. <h3 id="ServerList.SetServers">func (*ServerList) <a href="/?s=1473:1533#L41">SetServers</a></h3>
  150. <p><code>func (ss *ServerList) SetServers(servers ...string) os.Error</code></p>
  151. <p>
  152. SetServers changes a ServerList&#39;s set of servers at runtime and is
  153. threadsafe.
  154. </p>
  155. <p>
  156. Each server is given equal weight. A server is given more weight
  157. if it&#39;s listed multiple times.
  158. </p>
  159. <p>
  160. SetServers returns an error if any of the server names fail to
  161. resolve. No attempt is made to connect to the server. If any error
  162. is returned, no changes are made to the ServerList.
  163. </p>
  164. <h2 id="ServerSelector">type <a href="/?s=788:953#L20">ServerSelector</a></h2>
  165. <p>
  166. ServerSelector is the interface that selects a memcache server
  167. as a function of the item&#39;s key.
  168. </p>
  169. <p>
  170. All ServerSelector implementations must be threadsafe.
  171. </p>
  172. <p><pre>type ServerSelector interface {
  173. <span class="comment">// PickServer returns the server address that a given item</span>
  174. <span class="comment">// should be shared onto.</span>
  175. PickServer(key string) (net.Addr, os.Error)
  176. }</pre></p>
  177. <h2>Other packages</h2>
  178. <p>
  179. <a href="?p=main">main</a><br />
  180. </p>