Sunday, January 23, 2011

Easy data caching in Rails 3

Three common forms of caching

There are 3 types of caching that are very commonly talked about in the rails community; page caching, action caching, and fragment caching. All of these are well documented and are great ways to cache varying amounts of content for your pages.

Is that all the caching I need?

Caching at the view level is great but it isn't necessarily the best fit for every situation. In some cases it may be easier to cache data at a lower level. Perhaps you want to cache the results of an external data request for a given period of time. None of the view caching methods would be a really great fit.

Lower level data caching

Rails 3 actually has a great method for caching data at a lower level than the view. It even uses the same caching store as action and fragment caching. ActiveSupport::Cache::Store allows you to store any serializable Ruby object. Rails even provides an already initialized cache store via Rails.cache.

Example usage and code

I used this on www.checkthesock.com to cache METAR queries. I was using current_metar a gem I built that pulls metar data from ADDS. I made a model called CachedMetar to return cached results to the rest of my application.


Code walk through

This model basically returns the result of the block argument to Rails.cache.fetch the first time it is called. Any time it is called within the next 5 minutes it returns the value that was cached the first time. Everywhere I had previously been calling CurrentMetar::Metar.get_metar("ICAO code") I switched to call CachedMetar.metar("ICAO code") and that was all it took.

Testing

Testing is actually surprisingly easy. I used shoulda and mocha and here is what I ended up with.


Reference

122 comments:

Anonymous said...

Just to make a note: This feature has been documented and available in Rails (specifically, ActiveSupport) since version 2.1.0.

Unknown said...

Thanks for sharing. It is a worthwhile read for any app developer melbourne.

Anonymous said...

Nice information. Thank you for the explanation. It makes caching more understandable to us lay people.

James Daugherty

Unknown said...

Nice information. Thank you for the explanation.
cheap web hosting india
digital marketing Brisbane

reginald surict said...

Amazing blog. I also recommend you to have a look at this page to know how to spy whatsapp messages.

Unknown said...

This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It is the old thing going around comes around routine. https://meinehaarklinik.de/

Sri prathana said...

Nice information. Thank you for the explanation.

winter internship for ece students
electrical companies in hyderabad for internship
internship in indore for computer science students
free internship in chennai chennai, tamil nadu
free internship in chennai chennai, tamil nadu
internship for electrical engineering students in bangalore
internship in automobile industry
internship in chennai for mca
free ethical hacking course in chennai
paid internship in pune for computer engineering students

Sri prathana said...

cannot set headers after they are sent to the client
select * into sql server
number pattern program in python using while loop
which of the following numbers must be added to 5678 to give a reminder 35 when divided by 460?
riya sold her car for 50000
flipkart hack mod apk download
c program to print vowels in a string
the given signs signify something
two dimensional array in javascript w3schools
how to hack wifi using ubuntu

norhan said...


تنظيف منازل بالدمام شركة تنظيف
تنظيف منازل بالاحساء شركة تنظيف منازل بالاحساء
تنظيف منازل بمكة شركة تنظيف منازل بمكة
تنظيف منازل بجدة شركة تنظيف منازل بجدة
تنظيف منازل بالمدينة المنورة شركة تنظيف المنازل بالمدينة المنورة


subha said...

Some truly wonderful work on behalf of the owner of this internet site , perfectly great articles thansk a lot
Ai & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai

Priya said...

Great Post
Data Science Institutes In Hyderabad

EXCELR said...

Informative post. Glad to find yo ur blog. Thanks for sharing.data science course in Hyderabad

Excelr Tuhin said...

I've read this post and if I could I desire to suggest you some interesting things or suggestions. Perhaps you could write next articles referring to this article. I want to read more things about it!
data science course in Hyderabad

360DigiTMG said...

This is a great motivational article. In fact, I am happy with your good work. They publish very supportive data, really. Continue. Continue blogging. Hope you explore your next post
data scientist certification

Maneesha said...

I needed to leave a little remark to help you and wish you a decent continuation. Wishing you good luck for all your contributing to a blog endeavors.
data scientist training

360DigiTMGNoida said...

As always your articles do inspire me. Every single detail you have posted was great.
data science certification in noida

360DigiTMG said...

This post is very simple to read and appreciate without leaving any details out. Great work!
data science course

Datascience Course Analyst said...

Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.
Data Science Course in Bangalore

Unknown said...

Wow, amazing post! Really engaging, thank you.
best data analytics training in yelahanka

360digiTMG Training said...

I want to say thanks to you. I have bookmarked your site for future updates.
Best Data Science Courses in Hyderabad

Mallela said...

Thanks for posting the best information and the blog is very informative.Data science course in Faridabad

AI course in pune said...

I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.
artificial intelligence course in pune

data analytics books said...

I am a new user of this site, so here I saw several articles and posts published on this site, I am more interested in some of them, hope you will provide more information on these topics in your next articles.
data analytics training in bangalore

Data Scientist said...

Fantastic blog extremely good well enjoyed with the incredible informative content which surely activates the learners to gain the enough knowledge. Which in turn makes the readers to explore themselves and involve deeply in to the subject. Wish you to dispatch the similar content successively in future as well.

Data Science Course in Raipur

data scientist course said...

Wow what a Great Information about World Day its exceptionally pleasant educational post. a debt of gratitude is in order for the post.
data scientist course

Data Science said...

I am glad to discover this page. I have to thank you for the time I spent on this especially great reading !! I really liked each part and also bookmarked you for new information on your site.
Data Science Training in Chennai

Datascience Books said...

Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!
Data Science Training in Bangalore

Data Analytics Courses in Bangalore said...

I want to leave a little comment to support and wish you the best of luck.we wish the best best of luck in all your blogging endeavors.
data analytics course in bangalore

madhavi reddy said...

I Want to leave a little comment to support and wish you the best of luck.we wish you the best of luck in all your blogging endeavors.
data science in bangalore

AI Expert said...

I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got here. Big thumbs up for making such wonderful blog page!
artificial intelligence course in pune

360digiTMG Training said...


Very awesome!!! When I searched for this I found this website at the top of all blogs in search engines.

Best Institute for Data Science in Hyderabad

360DigiTMG said...

"Very Nice Blog!!!


Please have a look about "
data scientist malaysia

Data Science Course in Bhilai - 360DigiTMG said...

Truly mind blowing blog went amazed with the subject they have developed the content. These kind of posts really helpful to gain the knowledge of unknown things which surely triggers to motivate and learn the new innovative contents. Hope you deliver the similar successive contents forthcoming as well.

data science in bangalore

Anonymous said...

Thanks for sharing such nice info. I hope you will share more information like this. please keep on sharing!

Python Training In Bangalore | Python Online Training

Artificial Intelligence Training In Bangalore | Artificial Intelligence Online Training

Data Science Training In Bangalore | Data Science Online Training

Machine Learning Training In Bangalore | Machine Learning Online Training

AWS Training In Bangalore | AWS Online Training

IoT Training In Bangalore | IoT Online Training

Adobe Experience Manager (AEM) Training In Bangalore | Adobe Experience Manager (AEM) Online Training

Oracle Apex Training In Bangalore | Oracle Apex Online Training

Datascience Course Analyst said...

Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.
Data Science Course in Bangalore

Datascience Course Analyst said...

Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.
Data Science Course in Bangalore

Maneesha said...

This was not just great in fact this was really perfect your talent in writing was great.
data scientist training and placement

traininginstitute said...

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.

digital marketing courses in hyderabad with placement

InstituteBlr said...

Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.
Data Science Course in Bangalore

InstituteBlr said...

I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got here. Big thumbs up for making such wonderful blog page!
data analytics course in bangalore

traininginstitute said...

What a really awesome post this is. Truly, one of the best posts I've ever witnessed to see in my whole life. Wow, just keep it up.

best data science institute in hyderabad

360DigiTMGAurangabad said...

This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me..
machine learning certification in aurangabad

data analytics books said...

I am a new user of this site, so here I saw several articles and posts published on this site, I am more interested in some of them, hope you will provide more information on these topics in your next articles.
data analytics training in bangalore

traininginstitute said...

I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.
best data science institute in hyderabad

data analytics books said...

I am a new user of this site, so here I saw several articles and posts published on this site, I am more interested in some of them, hope you will provide more information on these topics in your next articles.
data analytics training in bangalore

traininginstitute said...

Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.
best data science institute in hyderabad

360DigiTMGAurangabad said...

Your content is very unique and understandable useful for the readers keep update more article like this.
data science course aurangabad

traininginstitute said...

I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
business analytics course

Data Science Expt said...

Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.
Data Science Course in Bangalore

Data Scientist said...

Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!
Data Science Training in Bangalore

traininginstitute said...

First You got a great blog .I will be interested in more similar topics. i see you got really very useful topics, i will be always checking your blog thanks.
best data science institute in hyderabad

360DigiTMG-Pune said...

This website and I conceive this internet site is really informative ! Keep on putting up!
data science course in pune

Mallela said...

Thanks for posting the best information and the blog is very important.data science institutes in hyderabad

Pallavi reddy said...

I am glad to discover this page. I have to thank you for the time I spent on this especially great reading !! I really liked each part and also bookmarked you for new information on your site.
artificial intellingence training in chennai

Maneesha said...

Just pure brilliance from you here. I have never expected something less than this from you and you have not disappointed me at all. I suppose you will keep the quality work going on.
data scientist training in hyderabad

Data Science Course in Bhilai - 360DigiTMG said...

Honestly speaking this blog is absolutely amazing in learning the subject that is building up the knowledge of every individual and enlarging to develop the skills which can be applied in to practical one. Finally, thanking the blogger to launch more further too.

data science course in bangalore with placement

Unknown said...

Fantastic article I ought to say and thanks to the info. Instruction is absolutely a sticky topic. But remains one of the top issues of the time. I love your article and look forward to more.
Data Science Course in Bangalore

DataScienceEXPO said...

Thank you quite much for discussing this type of helpful informative article. Will certainly stored and reevaluate your Website.
Data Science certification Course in Bangalore

DataBank said...

Nice to be seeing your site once again, it's been weeks for me. This article which ive been waited for so long. I need this guide to complete my mission inside the school, and it's same issue together along with your essay. Thanks, pleasant share.
Data Science training in Bangalore

DataCharge said...

Very wonderful informative article. I appreciated looking at your article. Very wonderful reveal. I would like to twit this on my followers. Many thanks! .
Data Science certification training in Bangalore

Mallela said...

Thanks for posting the best information and the blog is very important.digital marketing institute in hyderabad

traininginstitute said...

Great tips and very easy to understand. This will definitely be very useful for me when I get a chance to start my blog.
best data science institute in hyderabad

Mallela said...

Thanks for posting the best information and the blog is very important.artificial intelligence course in hyderabad

DataScienceEXPO said...

Thank you quite much for discussing this type of helpful informative article. Will certainly stored and reevaluate your Website.
Data Analytics Course in Bangalore

DataCharge said...

Very wonderful informative article. I appreciated looking at your article. Very wonderful reveal. I would like to twit this on my followers. Many thanks! .
Data Analytics training in Bangalore

traininginstitute said...

I want to say thanks to you. I have bookmarked your site for future updates.
business analytics course

lionelmessi said...

I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.

DevOps Training in Hyderabad

Pallavi reddy said...

i am glad to discover this page : i have to thank you for the time i spent on this especially great reading !! i really liked each part and also bookmarked you for new information on your site.
artificial intelligence training in chennai

Data Science Course in Bhilai - 360DigiTMG said...

Tremendous blog quite easy to grasp the subject since the content is very simple to understand. Obviously, this helps the participants to engage themselves in to the subject without much difficulty. Hope you further educate the readers in the same manner and keep sharing the content as always you do.

data science course in faridabad

traininginstitute said...

I truly like you're composing style, incredible data, thankyou for posting.
data science training

360DigiTMGAurangabad said...

"Very Nice Blog!!!


Please have a look about "
ai courses aurangabad

Priya Rathod said...

Excellent effort to make this blog more wonderful and attractive.
AWS Training in Hyderabad
AWS Course in Hyderabad

Priya Rathod said...

I'm glad to see the extensive unpretentious component here!.
Data Science Training in Hyderabad
Data Science Course in Hyderabad

traininginstitute said...

I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.
data science training

training institute said...

What a really awesome post this is. Truly, one of the best posts I've ever witnessed to see in my whole life. Wow, just keep it up.
data scientist course in malaysia

training institute said...

This is an excellent post I seen thanks to share it. It is really what I wanted to see hope in future you will continue for sharing such a excellent post.
data scientist course

Mallela said...

Thanks for posting the best information and the blog is very good.data science course in Lucknow

traininginstitute said...

Great tips and very easy to understand. This will definitely be very useful for me when I get a chance to start my blog.
data science course in malaysia

Unknown said...

I am a new user of this site, so here I saw several articles and posts published on this site, I am more interested in some of them, will provide more information on these topics in future articles.
data science course in london

Data Science said...

I am glad to discover this page. I have to thank you for the time I spent on this especially great reading !! I really liked each part and also bookmarked you for new information on your site.
Data Science Course in Gurgaon

Data Science said...

I am glad to discover this page. I have to thank you for the time I spent on this especially great reading !! I really liked each part and also bookmarked you for new information on your site.
Data Science Course in Delhi

Data Science said...

I am glad to discover this page. I have to thank you for the time I spent on this especially great reading !! I really liked each part and also bookmarked you for new information on your site.
Data Science Course in Noida

traininginstitute said...


The blog and data is excellent and informative as well
data science course in malaysia

Data Science said...

I am glad to discover this page. I have to thank you for the time I spent on this especially great reading !! I really liked each part and also bookmarked you for new information on your site.
Data Scientist Course in Delhi

tech science said...

I was just examining through the web looking for certain information and ran over your blog.It shows how well you understand this subject. Bookmarked this page, will return for extra. data science course in vadodara

Pallavi reddy said...

i am glad to discover this page : i have to thank you for the time i spent on this especially great reading !! i really liked each part and also bookmarked you for new information on your site.
data science training in noida

Unknown said...

I at last discovered extraordinary post here.I will get back here. I just added your blog to my bookmark locales. thanks.Quality presents is the vital on welcome the guests to visit the page, that is the thing that this website page is giving.cloud computing course in delhi

Pallavireddy said...

i am glad to discover this page : i have to thank you for the time i spent on this especially great reading !! i really liked each part and also bookmarked you for new information on your site.
data scientist course in nashik

manasa said...

That is truly great and supportive Information you have given, entirely significant substance. We are likewise into training and you additionally can exploit truly great work arranged courses…

Machine Learning Training in Hyderabad

traininginstitute said...

this is really nice to read..informative post is very good to read..thanks a lot!
data scientist course

Unknown said...

I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.best cyber security institute in delhi

Data Science said...

Amazingly by and large very interesting post. I was looking for such an information and thoroughly enjoyed examining this one. Keep posting. An obligation of appreciation is all together for sharing.data science colleges in bangalore

ideasontrend said...



Its a really interesting and informative article for me. I appreciate your work and skills. Emily in Paris Clothings

Data Science said...

Amazingly by and large very interesting post. I was looking for such an information and thoroughly enjoyed examining this one. Keep posting. An obligation of appreciation is all together for sharing.data science course in gwalior

Unknown said...

Fantastic article I ought to say and thanks to the info. Instruction is absolutely a sticky topic. But remains one of the top issues of the time. I love your article and look forward to more.
Data Science Course in Bangalore

DataBank said...

Nice to be seeing your site once again, it's been weeks for me. This article which ive been waited for so long. I need this guide to complete my mission inside the school, and it's same issue together along with your essay. Thanks, pleasant share.
Data Science training in Bangalore

DataScienceEXPO said...

Thank you quite much for discussing this type of helpful informative article. Will certainly stored and reevaluate your Website.
Data Analytics Course in Bangalore

360DigiTMG said...

Brilliant Blog! I might want to thank you for the endeavors you have made recorded as a hard copy of this post. I am trusting a similar best work from you later on also. I needed to thank you for these sites! Much obliged for sharing. Incredible sites!
data scientist course in hyderabad

Unknown said...

Very informative message! There is so much information here that can help any business start a successful social media campaign!
data science training in london

Diksha Gupta said...

I like your post. I appreciate your blogs because they are really good. Please go to this website for the Data Science Course: For Data Science course in Bangalore. These courses are wonderful for professionalism.

traininginstitute said...

It is extremely nice to see the greatest details presented in an easy and understanding manner.
full stack web development course in malaysia


Unknown said...

I truly appreciate just perusing the entirety of your weblogs. Just needed to educate you that you have individuals like me who value your work. Unquestionably an extraordinary post. Caps off to you! The data that you have given is exceptionally useful.data scientist course in bhopal

Ramesh Sampangi said...

Nice blog, thank for sharing with us.
Data Science Training in Hyderabad

Data Analytics Courses in Bangalore said...

I want to leave a little comment to support and wish you the best of luck.we wish you the best of luck in all your blogging enedevors
data science course delhi

data science said...

This post is easy to peruse and acknowledge without forgetting about any subtleties. Extraordinary work!

PMP Training in Malaysia said...

360DigiTMG, the top-rated organisation among the most prestigious industries around the world, is an educational destination for those looking to pursue their dreams around the globe. The company is changing careers of many people through constant improvement, 360DigiTMG provides an outstanding learning experience and distinguishes itself from the pack. 360DigiTMG is a prominent global presence by offering world-class training. Its main office is in India and subsidiaries across Malaysia, USA, East Asia, Australia, Uk, Netherlands, and the Middle East.

Data Science said...

Extremely overall quite fascinating post. I was searching for this sort of data and delighted in perusing this one.
Continue posting. A debt of gratitude is in order for sharing.
data analytics course in warangal

traininginstitute said...

wow, great, I was wondering how to cure acne naturally. and found your site by google, learned a lot, now i’m a bit clear. I’ve bookmark your site and keep us updated.
full stack web development course in malaysia

kumar said...

All things considered I read it yesterday yet I had a few musings about it and today I needed to peruse it again in light of the fact that it is very elegantly composed. data analytics courses malaysia

Data Science said...

Amazingly by and large very interesting post. I was looking for such an information and thoroughly enjoyed examining this one. Keep posting.
An obligation of appreciation is all together for sharing.data analytics course in gwalior

traininginstitute said...

Great tips and very easy to understand. This will definitely be very useful for me when I get a chance to start my blog.
full stack developer course

kumar said...

It's late discovering this demonstration. At any rate, it's a thing to be acquainted with that there are such occasions exist. I concur with your Blog and I will have returned to investigate it more later on so please keep up your demonstration.https://360digitmg.com/course/data-analytics-using-python-r

Anonymous said...

I want to leave a little comment to support and wish you the best of luck.we wish you the best of luck in all your blogging enedevors
data science course in trivandrum

Unknown said...

Amazing knowledge and I like to share this kind of information with my friends and hope they like it they why I do business analytics course in surat

Unknown said...

Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.business analytics course in bhubaneswar

360digiTMG.com said...

Has COVID-19 scare made you pause your career, join the best Data Science online course with 360DigiTMG and become a successful Data Scientist. data science training in chennai

360DigiTMG said...

Avail Data Science training and reach the epitome of success.
business analytics training in hyderabad

kumar said...

It is perfect chance to make a couple of game plans for the future and the opportunity has arrived to be sprightly. I've scrutinized this post and if I may I have the option to need to suggest you some interesting things or recommendations. Perhaps you could create next articles insinuating this article. I have to examine more things about it! Project Management Course

Professional Career Technology said...

Embark on a journey to achieve your professional goals by enrolling in the Data Scientist course in Bangalore. Learn the skills of collecting, extracting, analyzing, preparing, visualizing, and presenting results to make valuable decisions. Master the concepts of data science through hands-on projects and case studies to learn the latest trends and skills in this field.

Data Science Course in Bangalore with Placement

Career Program and Skill Development said...

The Data Sciences domain opened up many career opportunities for IT professionals. More and more IT professionals are looking for the best Data Science training to boost their careers. 360DigiTMG is the best place to start your technical training. We are equipped with a world-class curriculum to suit all your technical needs.

Best Data Science Training institute in Bangalore

Professional Academic Institute said...

Are you worried that joining in a top-rated Data Science course will burn a hole in your pocket, fret not 360DigiTMG offers Data Science courses that are pocket friendly. Enroll now to learn more about the course and fee details.

Data Science Course in Jaipur

datascience course said...

It would help if you learned programming and other fundamentals of computers that you can use throughout your life in any field you choose.data science course in kolkata