Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My cache is being flushed, why?

I'm having some problem with my app cache being flushed (page, action and fragment cache).

It looks like (according to the memcached IRC and the logfiles) the cache is being flushed very often, even though the cache isn't full.

I'm using:

  • memcached 1.4.5
  • rails 3.1.0.rc6
  • dalli 1.0.5

Here is data being printed when running stats using telnet.

I'm not using any expires_in options when saving data to the cache. Instead I use sweepers to flush the cache manually every night.

Anyone got an idea why this is happening?

like image 956
Linus Oleander Avatar asked Aug 25 '11 22:08

Linus Oleander


People also ask

What does cache flush mean?

When the amount of unwritten data in the cache reaches a certain level, the controller periodically writes cached data to a drive. This write process is called "flushing." The controller uses two algorithms for flushing cache: demand-based and age-based.

Why is cache flush required?

If flush is not carried out it may read junk data present in memory as the memory is not still updated with contents written to cache.

What does flushing the DNS cache do?

Whatever the case, you can "flush" your DNS cache to start from scratch, so your computer looks up web addresses on the DNS server again. This process is, of course, different from clearing your web cache from a web browser.

Should I flush cache?

In general, I recommend not clearing your cache unless you have a specific reason to. The files in the cache allow the websites you visit most often to load faster, which is a good thing. Your browser will periodically delete old files, so it's not like the cache is going to keep growing forever.


1 Answers

It looks like you're running out of memcached space:

STAT limit_maxbytes 262144000
STAT bytes          209406773

...causing data to be evicted from the cache when you don't want it to and the stats show that:

STAT evictions 94777

Looks like you've configured a 250mb cache size and you're using 80-90%.

Try increasing the cache size via -m option.

UPDATE:

The stats also show your cache being manually flushed via Rails.cache.clear (sending memcached flush_all):

STAT cmd_flush 4317 # Original Stat Capture
STAT cmd_flush 48   # New Stat Capture

You should search your codebase for manual cache flushes.

like image 187
Winfield Avatar answered Oct 08 '22 02:10

Winfield