how to use linecache.clearcache to clear the cache of a certain file?
<p>If I use linecache to read several files, and now the memory is to busy such that I want to clear a certain file cache rather than use 'linecache.clearcache()' to clear all the cache, what should I do?</p>

<p>I had the same consideration as you.</p>

<p>So I wrote the test codes by myself. You can check it out.</p>

<p><a href="https://ideone.com/xHxTEl" rel="nofollow">https://ideone.com/xHxTEl</a></p>

<p>Basically using <code>linecache.clearcache()</code> which is out of for-loop could be much faster but it would consume much more RAM the same time. The RAM sacrifices for the speed. The speed could be <strong>6 times faster</strong> comparing to clearing cache every time in the for-loop!!!</p>

<p>In contrast, you can use <code>linecache.clearcache()</code> in your for-loop. It took less memory but slow...</p>

<p>For me, I would clear the cache out of the for-loop and use multi-threads to chunk files into blocks. Extend the RAM and SWAP to be ready for the fast speed.</p>

python caching