O'Reilly logo

PHP and Smarty on Large-Scale Web Development by Vitor Rodrigues, Bruno Pedro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Optimization Techniques

Because sometimes things don't run as fast as you'd like them to, you must have some knowledge of optimization techniques. Basically, optimization at the application level is all about cache, but there are also other techniques to improve things generally.

Cache

Cache is one of the most important things in your application. A well-implemented cache system will boost the application performance and save you money on extra hardware.

When implementing cache, it's a good idea to divide it into two levels: the API and the presentation.

The API level is where all the business logic resides, with its code being shared by all the interfaces for your application, like web services, for instance. The presentation level is handled by Smarty, of course, and we discuss it in detail in the next section.

Although caching data might seem simple, there are several things you have to keep in mind when implementing and tuning the cache system. One of them is business logic. You have to make sure that all the data is consistent and follows the same rules.

Let's take a look at the Book application and pretend we are fetching the book data from a database. For the purpose of this example, we're also adding another property to the book named $sales.

In this example, we want to make sure that we get the right sales numbers, but we don't want to fetch them from the database every time we need them.

The solution is to cache the sales number's value, but whenever we get a new order, the cache ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required