<div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">In a case like this, I don&#39;t trust a cache miss to indicate presence<br>or absence of state. I prefer to keep separate key spaces: one for the
<br>positive case and one for the negative. Keep a representation of The<br>Truth in media with a stronger guarantee of data integrity [1]; as<br>states change, write through to memcached when recording The Truth and<br>upon cache misses, consult The Truth.
<br><br><br>[1] This could be an RDBMS, a Berkeley DB or something else. Which one<br>is correct depends on your scale, performance and concurrency<br>requirements.</blockquote></div>
<div>&nbsp;</div>
<div>I&#39;m already using a DB to store the members list.&nbsp; If you&#39;re proposing to use another layer of DB, wouldn&#39;t it be better to just do a DB query in the first place?</div>
<div><br><br>&nbsp;</div>
<div class="gmail_quote">On Nov 5, 2007 10:16 PM, Ian Kallen &lt;<a href="mailto:spidaman.list@gmail.com">spidaman.list@gmail.com</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">In a case like this, I don&#39;t trust a cache miss to indicate presence<br>or absence of state. I prefer to keep separate key spaces: one for the
<br>positive case and one for the negative. Keep a representation of The<br>Truth in media with a stronger guarantee of data integrity [1]; as<br>states change, write through to memcached when recording The Truth and<br>upon cache misses, consult The Truth.
<br><br><br>[1] This could be an RDBMS, a Berkeley DB or something else. Which one<br>is correct depends on your scale, performance and concurrency<br>requirements.<br>
<div>
<div></div>
<div class="Wj3C7c"><br>On 11/5/07, K J &lt;<a href="mailto:sanbat@gmail.com">sanbat@gmail.com</a>&gt; wrote:<br>&gt;<br>&gt; &gt; However, memcached semantics don&#39;t quite give you what you want.<br>&gt; &gt; Depending on whether you can reasonably get a configuration to do what
<br>&gt; &gt; you want, it might be easier to think of memcached as a bloom filter<br>&gt; &gt; than as a set in this case. &nbsp;That is, if you negatively cache things<br>&gt; &gt; that *aren&#39;t* part of your list, then the presence of a key will tell
<br>&gt; &gt; you for certain that a particular key is not a member, but the absence<br>&gt; &gt; of a key would mean that you don&#39;t know (or perhaps memcached *did*<br>&gt; &gt; know, but had since forgotten).<br>&gt;
<br>&gt;<br>&gt; I had thought of doing a bloom filter on it as well. &nbsp;The problem here is,<br>&gt; the membership list might change sometimes, and reading info on bloom<br>&gt; filters, it&#39;s not really well-suited for dynamically changing lists?
<br>&gt;<br>&gt; &gt; You could optionally preload objects that are likely to be used if<br>&gt; &gt; you think the natural population wouldn&#39;t do it effectively (you can<br>&gt; &gt; measure this with stats).<br>&gt; &gt;
<br>&gt;<br>&gt; Suppose I cache 10,000 recently-logged in members. &nbsp;Also, suppose 50% of<br>&gt; traffic actually come from these users. &nbsp;Then, this cache would have a high<br>&gt; hit ratio when testing for membership.<br>
&gt;<br>&gt; However, what about the non-members? &nbsp;For instance let&#39;s say 40% of the<br>&gt; traffic come from non-members. &nbsp;This would mean there&#39;d need to be a full<br>&gt; listing of members to check?<br>&gt;<br>
&gt; Hmmm an interesting thought did just come across my mind. &nbsp;Let me hear your<br>&gt; thoughts:<br>&gt;<br>&gt; Cache 10,000 most recently logged-in members<br>&gt; Bloom filter on the entire list<br>&gt; This way, you can test for negatives (bloom filter), and if there&#39;s a
<br>&gt; positive, check the 10,000 most recently logged-in users. &nbsp;If that still<br>&gt; yields nothing, then do a database query. &nbsp;In effect, only a small minority<br>&gt; of checks would require a trip to the DB.<br>&gt;
<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; On Nov 4, 2007, at 23:32, J A wrote:<br>&gt; &gt;<br>&gt; &gt; &gt; I have a fairly large members list that I want to keep in memcache.<br>
&gt; &gt; &gt; What I do with this list is query it against particular user IDs to<br>&gt; &gt; &gt; see if they are a member of that list or not. &nbsp;If they are they get<br>&gt; &gt; &gt; certain priviledges.<br>&gt; &gt; &gt;
<br>&gt; &gt; &gt; The problem is, this list has gotten to the point of saturating the<br>&gt; &gt; &gt; PHP&#39;s memory when fetching the MySQL query the first time.<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Is there a way to do this more effectively, for instance,
<br>&gt; &gt; &gt; partitioning the list into separate smaller lists, grouped by time<br>&gt; &gt; &gt; of login? &nbsp;I&#39;m thinking of this, as users who have logged in in the<br>&gt; &gt; &gt; past 3 months are more likely to be in the list anyway.
<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp;It&#39;d be easier to not think of it as a list if you&#39;re just testing<br>&gt; &gt; for membership. &nbsp;All you want to know is if a particular object is an<br>&gt; &gt; element of a particular set. &nbsp;You could do this by key convention if
<br>&gt; &gt; you batch populate the records.<br>&gt; &gt;<br>&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp;However, memcached semantics don&#39;t quite give you what you want.<br>&gt; &gt; Depending on whether you can reasonably get a configuration to do what
<br>&gt; &gt; you want, it might be easier to think of memcached as a bloom filter<br>&gt; &gt; than as a set in this case. &nbsp;That is, if you negatively cache things<br>&gt; &gt; that *aren&#39;t* part of your list, then the presence of a key will tell
<br>&gt; &gt; you for certain that a particular key is not a member, but the absence<br>&gt; &gt; of a key would mean that you don&#39;t know (or perhaps memcached *did*<br>&gt; &gt; know, but had since forgotten).<br>&gt; &gt;
<br>&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp;You could, of course, record the status either way so as to tell<br>&gt; the<br>&gt; &gt; difference between not knowing and knowing whether it&#39;s a member or<br>&gt; &gt; not. &nbsp;This is probably best suited to your needs.
<br>&gt; &gt;<br>&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp;You could optionally preload objects that are likely to be used if<br>&gt; &gt; you think the natural population wouldn&#39;t do it effectively (you can<br>&gt; &gt; measure this with stats).
<br>&gt; &gt;<br>&gt; &gt; --<br>&gt; &gt; Dustin Sallings<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt;<br>&gt;<br></div></div></blockquote></div><br>