<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Implementing a simple cache with Java</title>
	<atom:link href="http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/</link>
	<description>Writing about my experiences with technology and all different kinds of projects and experiments</description>
	<lastBuildDate>Mon, 30 Jan 2012 19:10:22 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: Christian Schenk</title>
		<link>http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/comment-page-1/#comment-49401</link>
		<dc:creator>Christian Schenk</dc:creator>
		<pubDate>Thu, 22 Dec 2011 07:14:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/#comment-49401</guid>
		<description>Hi Kamel,
if you&#039;re using a synchronized map you don&#039;t have to encapsulate it inside a synchronized block; the same holds true for a synchronized HashTable, which is just a certain implementation of a map.
If you checkout the code in the comment above in more detail you&#039;ll notice that two objects are altered inside the synchronized block. That said, the synchronized block makes sure that changing both objects is a single atomic operation.</description>
		<content:encoded><![CDATA[<p>Hi Kamel,<br />
if you&#8217;re using a synchronized map you don&#8217;t have to encapsulate it inside a synchronized block; the same holds true for a synchronized HashTable, which is just a certain implementation of a map.<br />
If you checkout the code in the comment above in more detail you&#8217;ll notice that two objects are altered inside the synchronized block. That said, the synchronized block makes sure that changing both objects is a single atomic operation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kamel</title>
		<link>http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/comment-page-1/#comment-48925</link>
		<dc:creator>Kamel</dc:creator>
		<pubDate>Mon, 19 Dec 2011 10:56:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/#comment-48925</guid>
		<description>Hi Christian,
Thanks so much about your code, I have noticed in comments we sill need to but synchronize block around maps when tries to remove. Can you please explain to me why I need that point as I can see you already creating synchronized map. or what if you used hashtable instead. Thanks</description>
		<content:encoded><![CDATA[<p>Hi Christian,<br />
Thanks so much about your code, I have noticed in comments we sill need to but synchronize block around maps when tries to remove. Can you please explain to me why I need that point as I can see you already creating synchronized map. or what if you used hashtable instead. Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christian Schenk</title>
		<link>http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/comment-page-1/#comment-48189</link>
		<dc:creator>Christian Schenk</dc:creator>
		<pubDate>Thu, 15 Dec 2011 15:14:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/#comment-48189</guid>
		<description>Dear Indrajit,
I&#039;m glad this post helped you. Don&#039;t forget to checkout the &lt;a href=&quot;http://data.christianschenk.org/implementing-a-simple-cache-with-java/xref/index.html&quot; rel=&quot;nofollow&quot;&gt;source code&lt;/a&gt; and play with it a bit - this way you&#039;ll probably understand the concepts even better.</description>
		<content:encoded><![CDATA[<p>Dear Indrajit,<br />
I&#8217;m glad this post helped you. Don&#8217;t forget to checkout the <a href="http://data.christianschenk.org/implementing-a-simple-cache-with-java/xref/index.html" rel="nofollow">source code</a> and play with it a bit &#8211; this way you&#8217;ll probably understand the concepts even better.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Indrajit Yadav</title>
		<link>http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/comment-page-1/#comment-48177</link>
		<dc:creator>Indrajit Yadav</dc:creator>
		<pubDate>Thu, 15 Dec 2011 14:14:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/#comment-48177</guid>
		<description>Hi All,

I am new for caching concept but after reading simple caching in java, and all your&#039;s comments i am happy it is giving more information to understand this concept and proceed further.

Thanks !</description>
		<content:encoded><![CDATA[<p>Hi All,</p>
<p>I am new for caching concept but after reading simple caching in java, and all your&#8217;s comments i am happy it is giving more information to understand this concept and proceed further.</p>
<p>Thanks !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brajendra N Mishra</title>
		<link>http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/comment-page-1/#comment-33287</link>
		<dc:creator>Brajendra N Mishra</dc:creator>
		<pubDate>Tue, 07 Jun 2011 12:48:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/#comment-33287</guid>
		<description>Thanks a Lot Christian,
I got what I needed.
It is described in very simple and precise manner. I like it. It would help me out in my exisiting project.</description>
		<content:encoded><![CDATA[<p>Thanks a Lot Christian,<br />
I got what I needed.<br />
It is described in very simple and precise manner. I like it. It would help me out in my exisiting project.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christian Schenk</title>
		<link>http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/comment-page-1/#comment-32763</link>
		<dc:creator>Christian Schenk</dc:creator>
		<pubDate>Thu, 26 May 2011 07:50:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/#comment-32763</guid>
		<description>Hi Maldalapu,
sure, that&#039;s one way to do it. You only need one synchronized block and won&#039;t have to add &lt;code&gt;synchronized&lt;/code&gt; to every method.</description>
		<content:encoded><![CDATA[<p>Hi Maldalapu,<br />
sure, that&#8217;s one way to do it. You only need one synchronized block and won&#8217;t have to add <code>synchronized</code> to every method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Maldalapu</title>
		<link>http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/comment-page-1/#comment-32721</link>
		<dc:creator>Maldalapu</dc:creator>
		<pubDate>Wed, 25 May 2011 11:26:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/#comment-32721</guid>
		<description>Here is what I have done:
&lt;pre lang=&quot;java&quot;&gt;
private void createRemoveRunnable(final K name) {
  synchronized (this) {
    cacheStore.remove(name);
    expire.remove(name);
  }
}
&lt;/pre&gt;

And is it required to keep synchronized block in &lt;code&gt;removeExpired()&lt;/code&gt; method ? If yes please let me know how do I do that ?</description>
		<content:encoded><![CDATA[<p>Here is what I have done:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> createRemoveRunnable<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> K name<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">synchronized</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    cacheStore.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    expire.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And is it required to keep synchronized block in <code>removeExpired()</code> method ? If yes please let me know how do I do that ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christian Schenk</title>
		<link>http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/comment-page-1/#comment-32694</link>
		<dc:creator>Christian Schenk</dc:creator>
		<pubDate>Tue, 24 May 2011 21:03:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/#comment-32694</guid>
		<description>Hi Maldalapu,
sure you can do this. Remember encapsulating these two operations in a &lt;code&gt;synchronized&lt;/code&gt; block, like it was mentioned earlier in the comments.</description>
		<content:encoded><![CDATA[<p>Hi Maldalapu,<br />
sure you can do this. Remember encapsulating these two operations in a <code>synchronized</code> block, like it was mentioned earlier in the comments.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Maldalapu</title>
		<link>http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/comment-page-1/#comment-32675</link>
		<dc:creator>Maldalapu</dc:creator>
		<pubDate>Tue, 24 May 2011 16:25:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/#comment-32675</guid>
		<description>Is it required to have a separate thread to remove entries from cache ? Like below 
&lt;pre lang=&quot;java&quot;&gt;
public void run() {
  cacheStore.remove(name);
  expire.remove(name);
}
&lt;/pre&gt;
Can&#039;t we keep the same inside after &lt;code&gt;threads.execute(createRemoveRunnable(name));&lt;/code&gt; in &lt;code&gt;removeExpired()&lt;/code&gt; method ?</description>
		<content:encoded><![CDATA[<p>Is it required to have a separate thread to remove entries from cache ? Like below</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  cacheStore.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  expire.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Can&#8217;t we keep the same inside after <code>threads.execute(createRemoveRunnable(name));</code> in <code>removeExpired()</code> method ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christian Schenk</title>
		<link>http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/comment-page-1/#comment-30259</link>
		<dc:creator>Christian Schenk</dc:creator>
		<pubDate>Tue, 19 Apr 2011 08:33:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/#comment-30259</guid>
		<description>Hi Rohit,
as the name implies &lt;code&gt;SimpleCache&lt;/code&gt; is a really simple solution to cache objects of a certain type. It isn&#039;t very sophisticated but may serve as a foundation for a more intelligent implementation.
In your case with lots and lots of records I could think of the following solutions:
&lt;ol&gt;
&lt;li&gt;limit the amount of cached objects and throw away the oldest objects on expiry not making any use of expiry after a certain amount of time.&lt;/li&gt;
&lt;li&gt;split the cache into various smaller segments that can be handled in a reasonable amount of time. Right now the implementation has got a map of objects and you could extend that to a map containing maps of objects. During the expiry run only work on a subset of these maps in the larger map.&lt;/li&gt;
&lt;/ol&gt;
Both solutions may help you limiting the set you will have to work on during an expiry run.</description>
		<content:encoded><![CDATA[<p>Hi Rohit,<br />
as the name implies <code>SimpleCache</code> is a really simple solution to cache objects of a certain type. It isn&#8217;t very sophisticated but may serve as a foundation for a more intelligent implementation.<br />
In your case with lots and lots of records I could think of the following solutions:</p>
<ol>
<li>limit the amount of cached objects and throw away the oldest objects on expiry not making any use of expiry after a certain amount of time.</li>
<li>split the cache into various smaller segments that can be handled in a reasonable amount of time. Right now the implementation has got a map of objects and you could extend that to a map containing maps of objects. During the expiry run only work on a subset of these maps in the larger map.</li>
</ol>
<p>Both solutions may help you limiting the set you will have to work on during an expiry run.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

