-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding template cache handling #146
base: gh-pages
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,3 +94,46 @@ global $user; | |
|
||
$user['favorite_colour'] = 'Blue'; | ||
``` | ||
|
||
## Caching Templates | ||
Don't forget to cache the template. This is important for pages with big load and prevent the database server from extra querys. | ||
|
||
### Caching a template | ||
An simple way to cache an template only at the place where it's needed, is to use the `THIS_SCRIPT` definition. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "An simple way" --> "A simple way" The general rule for a vs. an is that if the word after it starts with a vowel, Also, the comma here isn't necessary. "is to use..." is still part of the same clause. |
||
For example, the template is needed in the postbit. Then we can load it in the showthreads.php. | ||
```php | ||
if(THIS_SCRIPT == 'showthread.php') | ||
{ | ||
global $templatelist; | ||
if(isset($templatelist)) | ||
{ | ||
$templatelist .= ','; | ||
} | ||
$templatelist .= 'hello_world_template'; | ||
} | ||
``` | ||
Another example, here are some more templates needed on the member page. Then we can load it in the member.php. | ||
```php | ||
if(THIS_SCRIPT == 'member.php') | ||
{ | ||
global $templatelist; | ||
if(isset($templatelist)) | ||
{ | ||
$templatelist .= ','; | ||
} | ||
$templatelist .= ',hello_world_template_second'; | ||
$templatelist .= ',hello_world_template_third'; | ||
} | ||
``` | ||
|
||
### Testing if the template get cached | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "gets cached" or "got cached" or "templates get cached" |
||
You can simply test if the templates get cached correctly or not. Open the page where they should get cached and add a `?debug&debug=1` or `&debug&debug=1` to the url into the browser. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can test whether if templates get cached correctly or not with ease by opening the page where they should be cached and appending the Note that only administrators can access the debug page, so ensure you are logged in with an administrator account. |
||
Now you see the `MyBB Debug Information` page. The first table called `Page Generation Statistics` contain a row with the template cache information. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "the first table ... contain" --> "the first table ... contains" |
||
|
||
#### There is an template that not get cached: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider changing to "If a template does not get cached" or something and remove the colon. Headings don't need colons at the end of them. |
||
`No. Templates Used: 90 (89 Cached / 1 Manually Loaded)` | ||
This means there is 1 template that need an extra select query to the database to get loaded. At the botton you see the `Template Statistics` and now can control wich templates get not cached. All template names in `Templates Requiring Additional Calls (Not Cached at Startup) - 1 Total` are not cached, so you should correct your code. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "template that need an extra select query" --> "template that needs an extra select query" Typo: "wich" --> "which" "get not cached" --> "don't get cached" or "are not cached" or similar. |
||
|
||
#### If you do all right and the templates get cached at tho correct place it looks similar to: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps change to something like: "How to determine if templates are being cached correctly" Headings shouldn't be the dependent clause of what would otherwise be sentences. |
||
`No. Templates Used: 90 (90 Cached / 0 Manually Loaded)` | ||
Your template is now listed in the correct `Template Statistics` table. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
querys --> queries