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
11d374a8
Commit
11d374a8
authored
Jan 18, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finished cleanup of caching components.
parent
ce168fb3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
34 additions
and
36 deletions
+34
-36
Cache.php
framework/caching/Cache.php
+0
-0
ChainedDependency.php
framework/caching/ChainedDependency.php
+2
-2
DbCache.php
framework/caching/DbCache.php
+17
-23
DbDependency.php
framework/caching/DbDependency.php
+6
-3
FileCache.php
framework/caching/FileCache.php
+5
-5
MemCache.php
framework/caching/MemCache.php
+3
-2
ZendDataCache.php
framework/caching/ZendDataCache.php
+1
-1
No files found.
framework/caching/Cache.php
View file @
11d374a8
This diff is collapsed.
Click to expand it.
framework/caching/ChainedDependency.php
View file @
11d374a8
...
@@ -81,9 +81,9 @@ class ChainedDependency extends Dependency
...
@@ -81,9 +81,9 @@ class ChainedDependency extends Dependency
*/
*/
public
function
getHasChanged
()
public
function
getHasChanged
()
{
{
foreach
(
$this
->
dependencies
as
$dependency
)
{
foreach
(
$this
->
dependencies
as
$
i
=>
$
dependency
)
{
if
(
!
$dependency
instanceof
Dependency
)
{
if
(
!
$dependency
instanceof
Dependency
)
{
$dependency
=
\Yii
::
createObject
(
$dependency
);
$
this
->
dependencies
[
$i
]
=
$
dependency
=
\Yii
::
createObject
(
$dependency
);
}
}
if
(
$this
->
dependOnAll
&&
$dependency
->
getHasChanged
())
{
if
(
$this
->
dependOnAll
&&
$dependency
->
getHasChanged
())
{
return
true
;
return
true
;
...
...
framework/caching/DbCache.php
View file @
11d374a8
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
namespace
yii\caching
;
namespace
yii\caching
;
use
yii\base\Exception
;
use
yii\base\
InvalidConfig
Exception
;
use
yii\db\Connection
;
use
yii\db\Connection
;
use
yii\db\Query
;
use
yii\db\Query
;
...
@@ -57,7 +57,7 @@ class DbCache extends Cache
...
@@ -57,7 +57,7 @@ class DbCache extends Cache
public
$cacheTableName
=
'tbl_cache'
;
public
$cacheTableName
=
'tbl_cache'
;
/**
/**
* @var integer the probability (parts per million) that garbage collection (GC) should be performed
* @var integer the probability (parts per million) that garbage collection (GC) should be performed
* when storing a piece of data in the cache. Defaults to 10
0, meaning 0.
01% chance.
* when storing a piece of data in the cache. Defaults to 10
, meaning 0.0
01% chance.
* This number should be between 0 and 1000000. A value 0 meaning no GC will be performed at all.
* This number should be between 0 and 1000000. A value 0 meaning no GC will be performed at all.
**/
**/
public
$gcProbability
=
100
;
public
$gcProbability
=
100
;
...
@@ -69,7 +69,7 @@ class DbCache extends Cache
...
@@ -69,7 +69,7 @@ class DbCache extends Cache
/**
/**
* Returns the DB connection instance used for caching purpose.
* Returns the DB connection instance used for caching purpose.
* @return Connection the DB connection instance
* @return Connection the DB connection instance
* @throws Exception if [[connectionID]] does not point to a valid application component.
* @throws
InvalidConfig
Exception if [[connectionID]] does not point to a valid application component.
*/
*/
public
function
getDb
()
public
function
getDb
()
{
{
...
@@ -78,7 +78,7 @@ class DbCache extends Cache
...
@@ -78,7 +78,7 @@ class DbCache extends Cache
if
(
$db
instanceof
Connection
)
{
if
(
$db
instanceof
Connection
)
{
$this
->
_db
=
$db
;
$this
->
_db
=
$db
;
}
else
{
}
else
{
throw
new
Exception
(
"DbCache.connectionID must refer to the ID of a DB connection
application component."
);
throw
new
InvalidConfigException
(
"DbCache::connectionID must refer to the ID of a DB
application component."
);
}
}
}
}
return
$this
->
_db
;
return
$this
->
_db
;
...
@@ -163,13 +163,13 @@ class DbCache extends Cache
...
@@ -163,13 +163,13 @@ class DbCache extends Cache
*/
*/
protected
function
setValue
(
$key
,
$value
,
$expire
)
protected
function
setValue
(
$key
,
$value
,
$expire
)
{
{
$
query
=
new
Query
;
$
command
=
$this
->
getDb
()
->
createCommand
()
;
$command
=
$query
->
update
(
$this
->
cacheTableName
,
array
(
$command
->
update
(
$this
->
cacheTableName
,
array
(
'expire'
=>
$expire
>
0
?
$expire
+
time
()
:
0
,
'expire'
=>
$expire
>
0
?
$expire
+
time
()
:
0
,
'data'
=>
array
(
$value
,
\PDO
::
PARAM_LOB
),
'data'
=>
array
(
$value
,
\PDO
::
PARAM_LOB
),
),
array
(
),
array
(
'id'
=>
$key
,
'id'
=>
$key
,
))
->
createCommand
(
$this
->
getDb
())
;
))
;
;
if
(
$command
->
execute
())
{
if
(
$command
->
execute
())
{
$this
->
gc
();
$this
->
gc
();
...
@@ -198,16 +198,16 @@ class DbCache extends Cache
...
@@ -198,16 +198,16 @@ class DbCache extends Cache
$expire
=
0
;
$expire
=
0
;
}
}
$
query
=
new
Query
;
$
command
=
$this
->
getDb
()
->
createCommand
()
;
$command
=
$query
->
insert
(
$this
->
cacheTableName
,
array
(
$command
->
insert
(
$this
->
cacheTableName
,
array
(
'id'
=>
$key
,
'id'
=>
$key
,
'expire'
=>
$expire
,
'expire'
=>
$expire
,
'data'
=>
array
(
$value
,
\PDO
::
PARAM_LOB
),
'data'
=>
array
(
$value
,
\PDO
::
PARAM_LOB
),
))
->
createCommand
(
$this
->
getDb
())
;
));
try
{
try
{
$command
->
execute
();
$command
->
execute
();
return
true
;
return
true
;
}
catch
(
Exception
$e
)
{
}
catch
(
\
Exception
$e
)
{
return
false
;
return
false
;
}
}
}
}
...
@@ -220,10 +220,8 @@ class DbCache extends Cache
...
@@ -220,10 +220,8 @@ class DbCache extends Cache
*/
*/
protected
function
deleteValue
(
$key
)
protected
function
deleteValue
(
$key
)
{
{
$query
=
new
Query
;
$command
=
$this
->
getDb
()
->
createCommand
();
$query
->
delete
(
$this
->
cacheTableName
,
array
(
'id'
=>
$key
))
$command
->
delete
(
$this
->
cacheTableName
,
array
(
'id'
=>
$key
))
->
execute
();
->
createCommand
(
$this
->
getDb
())
->
execute
();
return
true
;
return
true
;
}
}
...
@@ -235,10 +233,8 @@ class DbCache extends Cache
...
@@ -235,10 +233,8 @@ class DbCache extends Cache
public
function
gc
(
$force
=
false
)
public
function
gc
(
$force
=
false
)
{
{
if
(
$force
||
mt_rand
(
0
,
1000000
)
<
$this
->
gcProbability
)
{
if
(
$force
||
mt_rand
(
0
,
1000000
)
<
$this
->
gcProbability
)
{
$query
=
new
Query
;
$command
=
$this
->
getDb
()
->
createCommand
();
$query
->
delete
(
$this
->
cacheTableName
,
'expire > 0 AND expire < '
.
time
())
$command
->
delete
(
$this
->
cacheTableName
,
'expire > 0 AND expire < '
.
time
())
->
execute
();
->
createCommand
(
$this
->
getDb
())
->
execute
();
}
}
}
}
...
@@ -249,10 +245,8 @@ class DbCache extends Cache
...
@@ -249,10 +245,8 @@ class DbCache extends Cache
*/
*/
protected
function
flushValues
()
protected
function
flushValues
()
{
{
$query
=
new
Query
;
$command
=
$this
->
getDb
()
->
createCommand
();
$query
->
delete
(
$this
->
cacheTableName
)
$command
->
delete
(
$this
->
cacheTableName
)
->
execute
();
->
createCommand
(
$this
->
getDb
())
->
execute
();
return
true
;
return
true
;
}
}
}
}
framework/caching/DbDependency.php
View file @
11d374a8
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
namespace
yii\caching
;
namespace
yii\caching
;
use
yii\base\Exception
;
use
yii\base\
InvalidConfig
Exception
;
use
yii\db\Connection
;
use
yii\db\Connection
;
use
yii\db\Query
;
use
yii\db\Query
;
...
@@ -68,6 +68,9 @@ class DbDependency extends Dependency
...
@@ -68,6 +68,9 @@ class DbDependency extends Dependency
protected
function
generateDependencyData
()
protected
function
generateDependencyData
()
{
{
$db
=
$this
->
getDb
();
$db
=
$this
->
getDb
();
/**
* @var \yii\db\Command $command
*/
$command
=
$this
->
query
->
createCommand
(
$db
);
$command
=
$this
->
query
->
createCommand
(
$db
);
if
(
$db
->
enableQueryCache
)
{
if
(
$db
->
enableQueryCache
)
{
// temporarily disable and re-enable query caching
// temporarily disable and re-enable query caching
...
@@ -83,7 +86,7 @@ class DbDependency extends Dependency
...
@@ -83,7 +86,7 @@ class DbDependency extends Dependency
/**
/**
* Returns the DB connection instance used for caching purpose.
* Returns the DB connection instance used for caching purpose.
* @return Connection the DB connection instance
* @return Connection the DB connection instance
* @throws Exception if [[connectionID]] does not point to a valid application component.
* @throws
InvalidConfig
Exception if [[connectionID]] does not point to a valid application component.
*/
*/
public
function
getDb
()
public
function
getDb
()
{
{
...
@@ -92,7 +95,7 @@ class DbDependency extends Dependency
...
@@ -92,7 +95,7 @@ class DbDependency extends Dependency
if
(
$db
instanceof
Connection
)
{
if
(
$db
instanceof
Connection
)
{
$this
->
_db
=
$db
;
$this
->
_db
=
$db
;
}
else
{
}
else
{
throw
new
Exception
(
"DbDependency.connectionID must refer to the ID of a DB connection
application component."
);
throw
new
InvalidConfigException
(
"DbCache::connectionID must refer to the ID of a DB
application component."
);
}
}
}
}
return
$this
->
_db
;
return
$this
->
_db
;
...
...
framework/caching/FileCache.php
View file @
11d374a8
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
namespace
yii\caching
;
namespace
yii\caching
;
use
yii\base\Exception
;
use
yii\base\
InvalidConfig
Exception
;
/**
/**
* FileCache implements a cache component using files.
* FileCache implements a cache component using files.
...
@@ -42,10 +42,10 @@ class FileCache extends Cache
...
@@ -42,10 +42,10 @@ class FileCache extends Cache
public
$directoryLevel
=
1
;
public
$directoryLevel
=
1
;
/**
/**
* @var integer the probability (parts per million) that garbage collection (GC) should be performed
* @var integer the probability (parts per million) that garbage collection (GC) should be performed
* when storing a piece of data in the cache. Defaults to 10
0, meaning 0.
01% chance.
* when storing a piece of data in the cache. Defaults to 10
, meaning 0.0
01% chance.
* This number should be between 0 and 1000000. A value 0 mean
ing
no GC will be performed at all.
* This number should be between 0 and 1000000. A value 0 mean
s
no GC will be performed at all.
**/
**/
public
$gcProbability
=
10
0
;
public
$gcProbability
=
10
;
/**
/**
* Initializes this component by ensuring the existence of the cache path.
* Initializes this component by ensuring the existence of the cache path.
...
@@ -55,7 +55,7 @@ class FileCache extends Cache
...
@@ -55,7 +55,7 @@ class FileCache extends Cache
parent
::
init
();
parent
::
init
();
$this
->
cachePath
=
\Yii
::
getAlias
(
$this
->
cachePath
);
$this
->
cachePath
=
\Yii
::
getAlias
(
$this
->
cachePath
);
if
(
$this
->
cachePath
===
false
)
{
if
(
$this
->
cachePath
===
false
)
{
throw
new
Exception
(
'FileCache.cachePath must be a valid path alias.'
);
throw
new
InvalidConfig
Exception
(
'FileCache.cachePath must be a valid path alias.'
);
}
}
if
(
!
is_dir
(
$this
->
cachePath
))
{
if
(
!
is_dir
(
$this
->
cachePath
))
{
mkdir
(
$this
->
cachePath
,
0777
,
true
);
mkdir
(
$this
->
cachePath
,
0777
,
true
);
...
...
framework/caching/MemCache.php
View file @
11d374a8
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
namespace
yii\caching
;
namespace
yii\caching
;
use
yii\base\Exception
;
use
yii\base\Exception
;
use
yii\base\InvalidConfigException
;
/**
/**
* MemCache implements a cache application component based on [memcache](http://pecl.php.net/package/memcache)
* MemCache implements a cache application component based on [memcache](http://pecl.php.net/package/memcache)
...
@@ -109,12 +110,12 @@ class MemCache extends Cache
...
@@ -109,12 +110,12 @@ class MemCache extends Cache
* @return \Memcache|\Memcached the memcache (or memcached) object used by this cache component.
* @return \Memcache|\Memcached the memcache (or memcached) object used by this cache component.
* @throws Exception if memcache or memcached extension is not loaded
* @throws Exception if memcache or memcached extension is not loaded
*/
*/
public
function
getMem
C
ache
()
public
function
getMem
c
ache
()
{
{
if
(
$this
->
_cache
===
null
)
{
if
(
$this
->
_cache
===
null
)
{
$extension
=
$this
->
useMemcached
?
'memcached'
:
'memcache'
;
$extension
=
$this
->
useMemcached
?
'memcached'
:
'memcache'
;
if
(
!
extension_loaded
(
$extension
))
{
if
(
!
extension_loaded
(
$extension
))
{
throw
new
Exception
(
"MemCache requires PHP
$extension
extension to be loaded."
);
throw
new
InvalidConfig
Exception
(
"MemCache requires PHP
$extension
extension to be loaded."
);
}
}
$this
->
_cache
=
$this
->
useMemcached
?
new
\Memcached
:
new
\Memcache
;
$this
->
_cache
=
$this
->
useMemcached
?
new
\Memcached
:
new
\Memcache
;
}
}
...
...
framework/caching/ZendDataCache.php
View file @
11d374a8
...
@@ -31,7 +31,7 @@ class ZendDataCache extends Cache
...
@@ -31,7 +31,7 @@ class ZendDataCache extends Cache
protected
function
getValue
(
$key
)
protected
function
getValue
(
$key
)
{
{
$result
=
zend_shm_cache_fetch
(
$key
);
$result
=
zend_shm_cache_fetch
(
$key
);
return
$result
!==
NULL
?
$result
:
false
;
return
$result
===
null
?
false
:
$result
;
}
}
/**
/**
...
...
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