Friday, September 16, 2011

Rails : Sweepers

The sweeper is a new mechanism inducted in rails which allows you to get around having a ton of expire_{page,action,fragment} calls in your code.It does this by moving all the work required to expire cached content into an ActionController::Caching::Sweeper subclass. This class is an observer and looks for changes to an object via callbacks, and when a change occurs it expires the caches associated with that object in an around or after filter.

Continuing with our Product controller example, we could rewrite it with a sweeper like this:

class ProductSweeper < ActionController::Caching::Sweeper observe Product # it keep watch on the Product Model # As soon as sweeper detects that any new Product was created call this def after_create(product) expire_cache_for(product) end # As soon as sweeper detects that a Product was updated call this def after_update(product) expire_cache_for(product) end # As soon as sweeper detects that a Product was deleted call this def after_destroy(product) expire_cache_for(product) end private def expire_cache_for(product) # Expire the index page now that we added a new product expire_page(:controller => 'products', :action => 'index')

# Expire a fragment
expire_fragment('all_available_products')
end
end

You may notice that the actual product gets passed to the sweeper, so if we were caching the edit action for each product, we could add an expire method which specifies the page we want to expire:

expire_action(:controller => 'products', :action => 'edit', :id => product)
Then we add it to our controller to tell it to call the sweeper when certain actions are called. So, if we wanted to expire the cached content for the list and edit actions when the create action was called, we could do the following:

class ProductsController < ActionController

before_filter :authenticate
caches_action :index
cache_sweeper :product_sweeper

def index
@products = Product.all
end

end

So just get rid of unnecessary caching and refresh the caching using sweepers mechanism.

ijab with ijabber under the hood of Openfire

What a fantastics chatting solution !!! Its works unimaginable. yes, its the webclient ijab (http://ijab.im) which works fantastics with jabber. No other chat can beat this solution. You can install the ijabber using openfire which provide the complete solution for managing all attributes and actions related to chat.

Both are opensource and available without any cost and very easy to install on the server.

References to both opensources:

(1)http://www.igniterealtime.org/projects/openfire/

(2)http://code.google.com/p/ijab/


Have a happy and fast chatting :)

Saturday, August 20, 2011

Cloud Computing Vs CDN ( Content Delivery Network )

There are many question which are arising regarding the servers. Which one is better and how long it will sustain ? . Currently two servers Cloud and CDN are majorly used in web Development. But what is the main difference between both ? The answer in nutshell is as below :-


The big difference is that cloud computing is a big group of servers in 1 data center building which is usually at one location. On the other hand CDN is also group of servers but distributed around the country so it allows web visitors a better and faster access to the website. For example if you're in Boston trying to access a server in California it can be faster to be hitting a server locally in Boston for the files. The CDN is usually able to support much larger traffic volumes since the speed is calculated based on location the traffic comes from.


So finally selection of the server will depends on your choice by looking the traffic on site and offcourse your budget also matters :)