CakePHP: Performance considerations

Source: Internet
Author: User
1. use $ uses and loadModel in CakePHP1.3.x to avoid using $ uses as much as possible, because this will load all the models used, occupying memory and consuming unnecessary time. Instead, use loadModel to load a model. Set the recursive Syn attribute when no data is associated.

1. use of $ uses and loadModel

In CakePHP1.3.x, try not to use $ uses, because this will load all the models used, occupying memory and consuming unnecessary time.

Instead, use loadModel to load a model. If you do not need to associate data, set the recursive attribute to-1.

In addition, the default data model of the controller does not need to be loaded. if users_controller does not need to call loadModel (User), the User model and its associated model are automatically loaded,

In the controller, you only need to use it directly:

$ This-> User ...;

$ This-> User-> Role...

With lazy loading technology, version 1.3 has a lazy_model that replaces the base class of your app_model with LazyModel,

The model will be loaded only in actual calls.

2. use of eval and requestAction

Do not use eval and requestAction whenever possible. Eval will cause a new script to parse the process, and requestAction is equivalent to sending a new request.

Eval can be replaced with a syntax similar to {} or $, as shown in figure

Case 1

$ This-> {$ this-> modelClass}-> hasField ("country_id ");

-----------------------------------------------------------------

Case 2

$ Foo = city;

$ Foo = shanghai;

Replace requestAction with view/helper

3. Cache

Memcached is used for distributed data sharing, and Apc is used for local data whenever possible. Specify the Cache configured in core. php by using the parameter where Cache: write/read is used.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.