Rails Memcached Caching - ruby-on-rails

I am using memcached in production on a high traffic website and have only just switched to using Rails.
I am using Rails 2.3.2.
My question is: Is caching of of queries done automatically with this version of Rails? Or do I have to explicitly cache these queries?
I have seen conflicting documentation on this issue, and I am afraid of having to restart memcached to see exactly what is happening.
The documentation on this w.r.t rails seems patchy. I would appreciate if you could also point out the best place to read up on this.
Thanks!
Vikram

If you haven't explicitly set out and configured certain actions to be cached they won't be, so I would guess right now that you aren't actually using your memcached like you think you are.
As a starting point I'd recommend reading this article on the different methods of setting up caching within Rails.
I've also found this presentation to be useful as well as this excellent screencast.
If you're looking for help, it would be useful to know more of what you're trying to do: how write heavy is the application? How may pages / views / users are you trying to serve?

Related

Can I use my web server to host my rails application?

I have now build my first Ruby on Rails site and I want to publish/deploy/show it to the world on internet. I have access to space on a web server trough a university that I am associated with. But after some searching I realized that publishing a Rails site is slightly more complicated than publishing a regular html production.
Is there any way to use the space I have? How can I know if the server I have access to is up for the task? Is there any guides on how to do this via SSH or git or whatever? I have search a lot but not found anything useful. It doesn't have to be easy, I just have to work. And it's good if I can learn and understand what I am doing.
I have tried quite extensively to make it work with Heroku (everybody claims it to be so easy) but failed since it will not accept my push. Probably because I use Rails 4.2.2 (I don't want to change this, too many things stopped working when I tried to update) and Paperclip which seems to be known issues.
Please, I'm getting desperate, any help pointing in the right direction is very appreciated.

What's the benefit of using Sinatra instead of RoR if I'm only need a DB and an API

I need to build a web service, for a mobile game, to manage the states of multiplayer games. I need a database and an RESTful API to access it. I'm very familiar with Ruby On Rails and was thinking of using that since I can throw together the DB and API pretty quickly. However, since RoR is a framework for building web pages and I'm not actually building any web pages, it naturally seems like the wrong technology to use even though it would work. As such, I'm considering using Ruby on Sinatra, but I've never used it before and I'll have to kill some time learning it. For you Ruby gurus, is there an advantage to using Sinatra or a disadvantage to using RoR for what I'm trying to accomplish?
Thanks so much in advance for your wisdom!
You know Rails, you don't know Sinatra. Personally I prefer the latter for things like building APIs, but there's nothing stopping you from doing it in Rails, and there's nothing intrinsically wrong with it either. Unless you want to see this as a learning opportunity for getting into Sinatra, I'd say stick with Rails. Here's some links that might be useful btw:
Building APIs With Rails
Building a Platform API on Rails
It probably depends on your API. If you need more than just a bunch of routes then you will have to come up with your own solutions (authentication, ...).
If all you need is some RESTfulness without the added weight, Sinatra is great. All you need to know is what happens in what route and you're fine. See the Sinatra Readme which has all the information to get started.

How to set a minimal Ruby page on a webserver that can add / edit / delete records?

I am trying to add a page on dreamhost.com to display
record = Record.find(params[:id]) # such as Record.find(1)
print record.content # to show content of this record
and that's it... probably using sqlite or mysql, and want to have the ability to add a record, similar to Ruby on Rails's scaffold.
If using Ruby on Rails, it is probably too big for such a simple purpose, but if I use Sinatra, then it looks like I have to start it on a port (and can't start it on port 80 because it is the dreamhost.com's port)
Can Sinatra or any tool or framework fit this purpose?
Go with Rails
Dreamhost offers Rails already installed and at no extra cost. And knowing Rails will certainly be more useful to you in the future than knowing Sinatra.
So, I don't see the benefit in Sinatra unless you are hosting the server.
Since Rails is a framework, it will give you a basic application easily, despite it's massive internal complexity.
I know this doesn't exactly answer the question, sorry about that, but on a shared-hosting site you will have limited opportunity to fiddle with the configuration. It's easier in this case to go with Rails.
Rails isn't really that heavyweight. Unless you need your "app" to be very high performance, Rails is probably a good solution that'll let you have this up in a matter of a couple hours.
That said, I'm sure Dreamhost has a way for you to run a Sinatra app within Phusion.
I wonder why nobody mentioned Padrino yet. It is lightweight and provides you with a simple admin interface!

how to use memcache to speed-up rails/heroku

Heroku supports memcache natively as an addon. my problem is, being a rails newbie still, I have no clue how to use memcache in order to speed-up my most time-consuming request (I know which they are by looking a the newrelic analysis). should we use a gem like 'cache-money' on-top of memcache? does anyone use act_as_cached anymore?
I know this is a pretty trivial questions. Yet after searching the web for hours, I could not find a decent tutorial. Any help/link appreciated!
You can watch Caching in Rails 2.1 and then read the memcached documentation (I suppose you have already read it) in Heroku.
Also, Touch and Cache is quite interesting technique to avoid writing Sweepers in order to delete cached content when you need to refresh the cached data. Using touch will auto expire cached data with almost no need to write new code.
Please note that today, the Heroku memcached integration assumes you are using Rails >= 2.3.3
The main idea is that you add the result(s) of your time consuming method to Rails.cache (which is the interface through which you access your caching mechanism). When you fetch that result(s) the caching mechanism searches to see if it can find it or if it hasn't expired.
If it finds it, it returns it very fast because it takes it from the cache.
If it doesn't find it or it has expired (you set this when you call fetch), it runs the actual slow method to add it or refresh it in cache.
Finally, it is very useful to read the Rails documentation apart from whether you are using memcached or the built in Rails caching: Caching with Rails: An overview. Among other things it talks about:
Page caching
Action caching
Fragment caching
Sweepers
SQL caching
and more ...
You can cache on memcache the action_cache or you can access to memcache with Rails.cache

Which CouchDB API to use for Rails?

I am currently investigating possible applications of CouchDB on my current project (written in Rails) and would like to get some feedback from people who have actually used these APIs. Which would you recommend and why?
ActiveCouch
CouchFoo
CouchRest
CouchRest-Rails
CouchPotato
The basic layer of CouchRest is probably the best to get started, CouchPotato is the most active for Rails integration, SimplyStored adds some nicities on top of CouchPotato
With Rails 3 use (or at least seriously consider using) CouchRest Model. It appears to be well maintained, since as of this update on 2013/12/19 I see several changes that are only 2 weeks old.
Before considering SimplyStored, you should note that they give this warning on Github:
Development work as stopped as we don't use SimplyStored anymore. Please do not expect any future commits and fixes.
Perhaps someone will pick it up, as it looks very useful.
I am going through the same process. You might find SimplyStored interesting if you haven't already given it a look.
http://github.com/peritor/simply_stored

Resources