<div dir="ltr">Hi John<br><div><div class="gmail_extra"><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>3.  If (1) and (2) are accurate, consider a situation where the CS is <b>full</b>.  When a data packet arrives, will doAfterInsert still be called?  Will an item in the content store be removed arbitrarily?  The reason I ask is because if doAfterInsert is called <b>after </b>the data packet has been added to the CS, then we're too late, right?  Something has been booted in order to make room.  But shouldn't we get to decide <i>before </i>the item is added?  How is this handled?</div></div></blockquote><div><br></div><div>If CS capacity is 1000 and already has 1000 entries,<br><ol><li>Cs::add will insert the entry. At this moment, CS contains 1001 entries.</li><li>cs::policy::doAfterInsert is invoked. It SHOULD evict at least one entry.</li><li>When Cs:add returns, CS contains no more than 1000 entries.<br></li></ol></div><div></div><div><br>I designed it this way, to save an invocation to the policy.<br></div><div>The alternative would be invoking the policy twice: once before inserting an entry to decide whether to accept the new entry and to make room if necessary, and once after inserting the entry to record the entry in the cleanup index.<br><br></div><div>The current insert-then-evict procedure is more efficient because the policy is invoked only once. This allows the policy to reuse internal variables when feasible. Although the CS can contain more entries than its "capacity", the final outcome (when Cs::add returns) is correct. Temporarily storing more entries than "capacity" during the execution of Cs::add is entirely an implementation detail because it is not observable from outside, given that the Cs class is not thread-safe so no other methods can be called until Cs::add returns.<br>Also, the "capacity" is enforced by the policy; the Cs class does not care about capacity. You can even make a policy that does nothing, in which case the CS will grow continously until NFD crashes due to out-of-memory.<br></div><div><br></div><div>Yours, Junxiao <br></div></div></div></div></div>