Time-based expiry of the Rails Page Cache

September 22nd, 2007 by Nikhil

Rails page caching is a great way to cope with a large number of hits. However, it’s hard to use in a typical web application cos parts of the page need to be personalized.

Even then, there are quite a few use cases where one could do a page cache for partials! Especially when using AJAX, the rendered partial at times is the same for all users. For example, when showing “related content”, the content displayed is related to the current article and not the viewer. In such a case one could use a page cache.

The only problem now is expiring the page cache. Computing “related content” is usually a time intensive operation when calculated from the other way, i.e. new content is added, so expire all pages to which it might be related to (so that it will appear as their related content the next time the partial is generated). Thus expiring the cache using sweepers isn’t an option. In such cases, a time based expiry works very well.

For this I have written a simple script using which you can specify which directory should be purged and at what time intervals.

Just download the cachedel script and drop it into your RAILS_ROOT/scripts directory

Then configure your cron to invoke it periodically.

Example:

0 * * * * /var/www/apps/c2w_portal/current/script/cachedel "blogs" 120This will invoke the cachedel script every hour and the script will delete all files in the blogs cache that are older than 2 hours

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...

Commoditization of Software Engineering

November 22nd, 2006 by Nikhil

As any practice matures, it’s practitioners try to find ways to drive up efficiency, quality and reduce risks and costs. Generally speaking, this leads to better and cheaper products. However, IT services companies seem to be taking this concept a bit too far.

Most tech organizations evolve processes that try to be predictable, cost effective and at the same time less dependent on people. The process relies more on roles such that any person can be cast into it. The processes warrant that people be replaceable since they aren’t predicable. The process maps software development into and assembly line. Read the rest of this entry »

3 Votes | Average: 3.67 out of 53 Votes | Average: 3.67 out of 53 Votes | Average: 3.67 out of 53 Votes | Average: 3.67 out of 53 Votes | Average: 3.67 out of 5 (3 votes, average: 3.67 out of 5)
Loading ... Loading ...

WTF….mistake or intended?

November 14th, 2006 by Khurshidali

Background

One of our existing client, lets call them TheClient, had a web based application for receiving orders from their dealers. The project was developed and maintained by a software company, lets call them TheITCompany.

For the past 5-6 years TheITCompany had been maintaining and enhancing the project for TheClient. The AMC for the project was due for renewal in coming few months when TheITCompany informed TheClient that they would have to pay a higher cost for the next AMC renewal.
As this did not fit TheClient’s budget, they wanted to end the contract with TheITCompany and find a new IT partner for managing this project. Because of the previous work done for them they contacted us and offered us the job.

The Maintenance

The maintenance contract was signed with us and we had started the support. One day we received a call from TheClient saying that their order screen, which is supposed to accept address along with other things, is not working properly. Even after entering proper value they were not stored correctly in the database. They also informed that the problem was not there previously and had only started after TheITCompany released some changes during the last few days of their AMC period.
Investigating more on this revealed that the order screen had 2 address lines before. The html code snippet for the address fields looked something like below.

Listing 1

address_form1.jpg

TheClient wanted one more field Address Line 3 to be added to the system. TheITCompany had made the requested changes and deployed it on the production server without taking approval from TheClient. As per TheClient this resulted in goods being delivered to locations different from what was actually intended.

Although the task was simple to add a new field, it was done ridiculously. Diggng into the source code revealed some disturbing things. The new html snippet for the address fields looked something like below.
Listing 2

address_form2.jpg

From the above one can see that although they had added the new address line field they had unnecessary shuffled the existing fields which were working properly. I fail to understand the logic behind this.

This was not the end. Further investigation revealed that some piece of code which was responsible for instantiating the Address object for saving to the database looked something like this.

Listing 3

Address deliveryAddress = new Address(
somefields..,
request.getParameter("name"),
“”,
request.getParameter(”address2″),
somemorefields..,
request.getParameter(”address3″)
);

The above constructor had the signature given below
Listing 4

public Address(
somefields...,
String name,
String address1,
String address2,
somemorefields..,
String address3) ;

If you look closely at Listing 3 you will see that the address1 argument was passed a hardcoded blank value. I assume this was not the case before because as TheClient mentioned things were working fine before they made the change.
In summary the cumulative effect of code in Listing 2 and Listing 3 was as below

  • What the user entered as Address line 1 was stored in address2 field in database
  • What the user entered as Address line 2 was stored in address3 field in database
  • What the user entered as Address line 3 should have been stored in the address1 field as per the form(Listing 2) but the code responsible for actually collecting the form fields(Listing 3) just ignored the address1 field.

I want to remind everyone that the TheClient’s requirement was to “just add a new field Address Line 3 on the form”. There was no logical reason why existing fields should have been renamed and moved around.

I feel that maybe the above WTF was not a result of programming error but was Intended to leave the client sailing on rough seas. Maybe the reason for doing this was to force the client to renew the AMC even at a higher cost. I have a strong feeling that this was the case because however dumb a developer may be the above mess looks difficult to achieve.

There is a slight chance that this was a programming error. If this is the case then also its a big shame for TheITCompany. FYI this is a company based in India with branches in many countries, having an employee strength of more than 3000 and serving many big clients. Besides they have a whole section on their website dedicated to “Quality” and “Processes”. They also claim that they incorporate the best practices from SEI CMM, ISO, IEEE.. etc which is supposed to optimize their process and improve it. Even after following these so called best practices if they cannot deliver a decent working software then who is to blame?

2 Votes | Average: 2 out of 52 Votes | Average: 2 out of 52 Votes | Average: 2 out of 52 Votes | Average: 2 out of 52 Votes | Average: 2 out of 5 (2 votes, average: 2 out of 5)
Loading ... Loading ...

Self-Centered Software Design

November 13th, 2006 by Nikhil

Dog and CatIt’s well known that most software developers hate providing support, training end users, writing documentation, basically anything that doesn’t involve programming. But when you force them to do what they hate the most, you can expect dramatic improvements in the software that they create.
It’s kinda like If you are a dog who makes cat food, let the cats come to you if they need to throw-up.
Read the rest of this entry »

4 Votes | Average: 5 out of 54 Votes | Average: 5 out of 54 Votes | Average: 5 out of 54 Votes | Average: 5 out of 54 Votes | Average: 5 out of 5 (4 votes, average: 5 out of 5)
Loading ... Loading ...

Microsoft’s Desktop Irony

November 10th, 2006 by Nikhil

Steve Ballmer is currently in India and has made the headlines of todays Economic Times. Apart from the usual Google/Oracle/Apple/IBM bashing, he vehemently defends the desktop. That’s logical since Microsoft’s main moolah generating engine is powered by the desktop. Isn’t it then ironic, that the one innovative thing to come out of Microsoft - XMLHTTPRequest (backbone of AJAX), is directly aimed at reducing the desktop to merely a device sporting a terminal, keyboard and mouse. Read the rest of this entry »

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...

In defense of J2EE’s complexity

November 7th, 2006 by Nikhil

EinsteinJ2EE bashing seems to be the flavour these days. While I do agree that J2EE does seem tedious at times, especially when you compare it with the likes of Ruby on Rails, I still realize (and appreciate) why and how J2EE got to be the way it is.

Read the rest of this entry »

24 Votes | Average: 3.29 out of 524 Votes | Average: 3.29 out of 524 Votes | Average: 3.29 out of 524 Votes | Average: 3.29 out of 524 Votes | Average: 3.29 out of 5 (24 votes, average: 3.29 out of 5)
Loading ... Loading ...

Ruby, A Samurai’s Sword

November 5th, 2006 by Nikhil

KatanaI like to think of Ruby as a weapon. A weapon with which I can attack problems my way! Ruby appears simple, and convenient, and hence poses a question; Why aren’t enough techies using it?

That’s when I realized - Ruby is like a Samurai’s sword, a Katana. Not of much use to the corporate coder, but in the right hands, extremely effective. Read the rest of this entry »

4 Votes | Average: 4 out of 54 Votes | Average: 4 out of 54 Votes | Average: 4 out of 54 Votes | Average: 4 out of 54 Votes | Average: 4 out of 5 (4 votes, average: 4 out of 5)
Loading ... Loading ...

Why we don’t have any customers

October 28th, 2006 by Rajesh

We don’t have customers. We have clients. We only want clients and not customers.

Don’t customer and client mean the same? It doesn’t to us because there is a fundamental and practical difference between the two. This understanding that there is a difference between a Customer and a Client forms the foundation of our business deals and guides us in our business. Let me explain further our philosophy to have ONLY Clients?
Read the rest of this entry »

5 Votes | Average: 4.8 out of 55 Votes | Average: 4.8 out of 55 Votes | Average: 4.8 out of 55 Votes | Average: 4.8 out of 55 Votes | Average: 4.8 out of 5 (5 votes, average: 4.8 out of 5)
Loading ... Loading ...

Future of Enterprise Content Management

October 6th, 2006 by Nikhil

An Information System’s key purpose is to manage and serve information to it’s users. Thus information storage and retrieval is at the heart of any IT system. Most systems use Relational Databases (RDBMS) for this purpose.

As technology matures, software development tools progress towards working in the business domain. As an example, programming languages have come a long way from machine code to assembly language to procedural languages and now to object-oriented languages and 4GL. I don’t see why data storage, retrieval and management shouldn’t follow the same evolution cycle. In the past developers used punched cards, followed by flat files and moved to relational databases for data storage and have been stuck at relational databases for around 20 years now. Read the rest of this entry »

3 Votes | Average: 4.67 out of 53 Votes | Average: 4.67 out of 53 Votes | Average: 4.67 out of 53 Votes | Average: 4.67 out of 53 Votes | Average: 4.67 out of 5 (3 votes, average: 4.67 out of 5)
Loading ... Loading ...