Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
972173a5
Commit
972173a5
authored
May 19, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
guide WIP [skip ci]
parent
5fdc3d40
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
80 deletions
+2
-80
caching-data.md
docs/guide/caching-data.md
+0
-0
caching-overview.md
docs/guide/caching-overview.md
+2
-80
No files found.
docs/guide/caching-data.md
View file @
972173a5
This diff is collapsed.
Click to expand it.
docs/guide/caching-overview.md
View file @
972173a5
...
@@ -3,7 +3,7 @@ Caching
...
@@ -3,7 +3,7 @@ Caching
Caching is a cheap and effective way to improve the performance of a Web application. By storing relatively
Caching is a cheap and effective way to improve the performance of a Web application. By storing relatively
static data in cache and serving it from cache when requested, the application saves the time that would be
static data in cache and serving it from cache when requested, the application saves the time that would be
required to generate the data from scratch.
required to generate the data from scratch
every time
.
Caching can occur at different levels and places in a Web application. On the server side, at the lower level,
Caching can occur at different levels and places in a Web application. On the server side, at the lower level,
cache may be used to store basic data, such as a list of most recent article information fetched from database;
cache may be used to store basic data, such as a list of most recent article information fetched from database;
...
@@ -11,86 +11,8 @@ and at the higher level, cache may be used to store the page content, such as th
...
@@ -11,86 +11,8 @@ and at the higher level, cache may be used to store the page content, such as th
recent articles. On the client side, HTTP caching may be used to keep most recently visited page content in
recent articles. On the client side, HTTP caching may be used to keep most recently visited page content in
the browser cache.
the browser cache.
Yii supports all these caching mechanisms
which are described in the following sections
:
Yii supports all these caching mechanisms:
*
[
Data caching
](
caching-data.md
)
*
[
Data caching
](
caching-data.md
)
*
[
Content caching
](
caching-content.md
)
*
[
Content caching
](
caching-content.md
)
*
[
HTTP caching
](
caching-http.md
)
*
[
HTTP caching
](
caching-http.md
)
## Cache Components
Server-side caching (data caching and content caching) relies on the so-called
*cache components*
.
Each cache component represents a caching storage and provides a common set of APIs
that may be called to store data in the cache and retrieve it later.
Cache components are usually registered as application components so that they can be globally
configurable and accessible. You may register multiple cache components in a single application.
In most cases you would configure at least the
[
[yii\base\Application::getCache()|cache
]
] component
because it is the default cache component being used by most cache-dependent classes, such as
[
[yii\web\UrlManager
]
].
The following code shows how to configure the
`cache`
application component to
use
[
memcached
](
http://memcached.org/
)
with two cache servers:
```
php
'components'
=>
[
'cache'
=>
[
'class'
=>
'yii\caching\MemCache'
,
'servers'
=>
[
[
'host'
=>
'server1'
,
'port'
=>
11211
,
'weight'
=>
100
,
],
[
'host'
=>
'server2'
,
'port'
=>
11211
,
'weight'
=>
50
,
],
],
],
],
```
You may access the
`cache`
component by using the expression
`Yii::$app->cache`
.
The following is a summary of the built-in cache components supported by Yii:
*
[
[yii\caching\ApcCache
]
]: uses PHP
[
APC
](
http://php.net/manual/en/book.apc.php
)
extension. This option can be
considered as the fastest one when dealing with cache for a centralized thick application (e.g. one
server, no dedicated load balancers, etc.).
*
[
[yii\caching\DbCache
]
]: uses a database table to store cached data. To use this cache, you must
create a table as specified in
[
[yii\caching\DbCache::cacheTable
]
].
*
[
[yii\caching\DummyCache
]
]: serves as a cache placeholder which does no real caching.
The purpose of this component is to simplify the code that needs to check the availability of cache.
For example, during development or if the server doesn't have actual cache support, you may configure
a cache component to use this cache. When an actual cache support is enabled, you can switch to use
the corresponding cache component. In both cases, you may use the same code
`Yii::$app->cache->get($key)`
to attempt retrieving data from the cache without worrying that
`Yii::$app->cache`
might be
`null`
.
*
[
[yii\caching\FileCache
]
]: uses standard files to store cached data. This is particular suitable
to cache large chunk of data, such as page content.
*
[
[yii\caching\MemCache
]
]: uses PHP
[
memcache
](
http://php.net/manual/en/book.memcache.php
)
and
[
memcached
](
http://php.net/manual/en/book.memcached.php
)
extensions. This option can be considered as
the fastest one when dealing with cache in a distributed applications (e.g. with several servers, load
balancers, etc.)
*
[
[yii\redis\Cache
]
]: implements a cache component based on
[
Redis
](
http://redis.io/
)
key-value store
(redis version 2.6.12 or higher is required).
*
[
[yii\caching\WinCache
]
]: uses PHP
[
WinCache
](
http://iis.net/downloads/microsoft/wincache-extension
)
(
[
see also
](
http://php.net/manual/en/book.wincache.php
)
) extension.
*
[
[yii\caching\XCache
]
]: uses PHP
[
XCache
](
http://xcache.lighttpd.net/
)
extension.
*
[
[yii\caching\ZendDataCache
]
]: uses
[
Zend Data Cache
](
http://files.zend.com/help/Zend-Server-6/zend-server.htm#data_cache_component.htm
)
as the underlying caching medium.
> Because all cache components extend from the same base class [[yii\caching\Cache]], you can switch to use
a different type of cache without modifying the code that uses a cache.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment