<div dir="ltr"><div class="gmail_default" style="color:#660000">On the subject of maxiumum cache size - I like being able to limit the memory usage, but there is apparently no way to prioritize often used entries.  I'm thinking of an example where my cache is full, having gone through every entry, but then a small subset of entries is frequently read which may not have been the first into the cache.  If I understand the wording of the wiki article correctly, these would then not benefit from caching, since they would not be allowed in the cache?</div><div class="gmail_default" style="color:#660000"><br></div><div class="gmail_default" style="color:#660000">Also, I'm unclear on the differences between the three object expire/lifetime values.  Can you add more descriptive details to each of these values, possibly give an example showing why it is beneficial?</div><div class="gmail_default" style="color:#660000"><br></div><div class="gmail_default" style="color:#660000">My thoughts on cache needs are this:</div><div class="gmail_default" style="color:#660000"><br></div><div class="gmail_default" style="color:#660000">1) I want to be able to set the maximum memory dedicated to caching, either in MB or in # of entries, but have the caching algorithm take into account the most recently read entries when determining what to hold onto and what to throw away.  Something I've just looked up is more likely to used again than something that has been sitting in the cache for a while.  To accomplish this each entry needs a timestamp of the last cache hit (when it was last used/read).</div><div class="gmail_default" style="color:#660000"><br></div><div class="gmail_default" style="color:#660000">2) I want to be able to set two maximum time in cache values: The first is the seconds after which the entry is stale, and the second where it is guarunteed to be removed from the cache and no longer used.  Both values are from the time the entry was last obtained from the source (db), requiring a timestamp on entry creation or when it was last refreshed from the source.  Before the entry is stale, it can be re-used without any further action needed.  When a stale entry is accessed (the first time) it should trigger a background refresh to ensure that changes have not been made, but continue to return a hit from the cache until the second timeout.  Background refreshes to be initiated by a separate thread only when there are no primary requests active.  The idea here is I can set 300 seconds for stale, and 600 for lifetime -- for a frequently used entry I'm only refreshing from the database every 2.5 minutes and 100% of the requests come immediately from the cache with no database lookup delay to the requesting thread.  For any entry that hasn't been read in 5 minutes, it's deleted so the memory utilization goes away also.</div><div class="gmail_default" style="color:#660000"><br></div><div class="gmail_default" style="color:#660000">3) Flushing all entries on a periodic interval doesn't sound like an option I'd be interested in -- assuming that a maximum time in cache is enforced properly, this seems like an odd duplication.  My worry is that dumping all the entries will occasionally occur in the middle of a burst of reads, and thus significantly slow things down.</div><div class="gmail_default" style="color:#660000"><br></div><div class="gmail_default" style="color:#660000">4) The external notification should be able to forcibly empty the cache, or optionally instead just force all objects to be stale without removing them.  This would require adding a stale flag to the entry.</div><div class="gmail_default" style="color:#660000"><br></div><div class="gmail_default" style="color:#660000">5) The rebalancing option sounds like a good idea, but since it is such an implementation specific value, it would be useful to run some tests and document some statistics on what conditions are needed for it to go from negligable to noticeable improvement, so that people have an idea of when and how to use it.</div><div class="gmail_default" style="color:#660000"><br></div><div class="gmail_default" style="color:#660000"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 28, 2015 at 11:28 AM, Joshua Colp <span dir="ltr"><<a href="mailto:jcolp@digium.com" target="_blank">jcolp@digium.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Kia ora,<br>
<br>
I've created a wiki page[1] which details the beginnings of a basic memory based caching wizard for sorcery. Right now while caching is possible using the existing memory wizard it's not possible to define object lifetimes, so once cached it's always pulled from the cache. This wiki page uses the memory wizard as a base but defines options which can tweak the behavior. Going forward this could serve as a basis for other wizards to be created for caching purposes.<br>
<br>
Some things to consider:<br>
1. How much control and flexibility should we allow?<br>
2. Are there additional mechanisms that should be exposed to allow explicit object expiration?<br>
3. Are the defaults sane?<br>
4. Is there additional testing that should be done?<br>
5. Does anything need additional explanation?<br>
<br>
Cheers,<br>
<br>
[1] <a href="https://wiki.asterisk.org/wiki/display/~jcolp/Sorcery+Caching" target="_blank">https://wiki.asterisk.org/wiki/display/~jcolp/Sorcery+Caching</a><span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
Joshua Colp<br>
Digium, Inc. | Senior Software Developer<br>
445 Jan Davis Drive NW - Huntsville, AL 35806 - US<br>
Check us out at: <a href="http://www.digium.com" target="_blank">www.digium.com</a> & <a href="http://www.asterisk.org" target="_blank">www.asterisk.org</a><br>
<br>
-- <br>
_____________________________________________________________________<br>
-- Bandwidth and Colocation Provided by <a href="http://www.api-digital.com" target="_blank">http://www.api-digital.com</a> --<br>
<br>
asterisk-dev mailing list<br>
To UNSUBSCRIBE or update options visit:<br>
  <a href="http://lists.digium.com/mailman/listinfo/asterisk-dev" target="_blank">http://lists.digium.com/mailman/listinfo/asterisk-dev</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><img alt="Digium logo" src="https://my.digium.com/images/graphics/digium_RGB_signature.gif" width="288" height="50" style="color:rgb(0,0,0);font-family:Arial,Helvetica,sans-serif;font-size:12px"><div>Scott Griepentrog<br>Digium, Inc · Software Developer<br>445 Jan Davis Drive NW · Huntsville, AL 35806 · US<br>direct/fax: +1 256 428 6239 · mobile: +1 256 580 6090<br>Check us out at: <a href="http://digium.com" target="_blank">http://digium.com</a> · <a href="http://asterisk.org" target="_blank">http://asterisk.org</a><br></div></div></div>
</div>