Regarding the daemon part of your application, I've done something similar
before, and used a combination of Rails-based rake tasks triggered by
Chronic or something similar.  I didn't have the need to manage the cache as
you're describing, but including a task that refreshes cached information
and running it after each update would probably be simple enough.

On Tue, Feb 22, 2011 at 10:59 AM, Frederick Cheung <
frederick.che...@gmail.com> wrote:

>
>
> On Feb 22, 9:33 am, Ram Kumar <li...@ruby-forum.com> wrote:
> > Hi,
> >
> > I am new to Rails and I am building a rails server which acts as the
> > backend for a mobile app. I have certain daemon processes that fetch and
> > store data in a database. Every time someone makes a request for data
> > from the phone, I will have to send him the same dataset irrespective of
> > who is requesting the data.
> >
> > This dataset will keep changing quite frequently and my daemons will
> > keep updating the database accordingly. Since the same data is to be
> > sent to every one, I am assuming that it would be best to cache the data
> > on the server and keep updating the cache at a set frequency (thus
> > making only one trip to the db). When I get a request from the phone, I
> > just retrieve this cached dataset and send it back, w/o hitting the db.
> >
> > I think one way of doing this would be to use a singleton model class
> > which will cache the data and this would act as the source. Is this the
> > best way to go about this process? Does Rails provide some other means
> > of doing this?
>
> Rails provides Rails.cache which is an abstraction round several
> different data stores. Personally i wouldn't usually recommend the in
> memory cache you're considering. It means that you have as many copies
> of the data in memories as you have mongrels/passenger instances etc,
> ie you are fetching the data more often than you need. It also makes
> it difficult for you to force expiry of the cache. Most people use
> something like memcache for this job (one of the cache stores
> Rails.cache supports is a memcache store).
>
> You may also want to consider caching at different levels in the
> stack, for example by putting something like varnish in front of your
> web servers.
>
> Fred
> >
> > Thanks,
> >
> > Ramkumar.
> >
> > --
> > Posted viahttp://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to