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
427c373b
Commit
427c373b
authored
Aug 27, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement Cache::exists() for various cache backends
fixes #811
parent
3b91801a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
97 additions
and
1 deletion
+97
-1
DbCache.php
framework/yii/caching/DbCache.php
+29
-0
FileCache.php
framework/yii/caching/FileCache.php
+20
-0
RedisCache.php
framework/yii/caching/RedisCache.php
+15
-0
WinCache.php
framework/yii/caching/WinCache.php
+17
-1
XCache.php
framework/yii/caching/XCache.php
+16
-0
No files found.
framework/yii/caching/DbCache.php
View file @
427c373b
...
...
@@ -89,6 +89,35 @@ class DbCache extends Cache
}
/**
* Checks whether a specified key exists in the cache.
* This can be faster than getting the value from the cache if the data is big.
* Note that this method does not check whether the dependency associated
* with the cached data, if there is any, has changed. So a call to [[get]]
* may return false while exists returns true.
* @param mixed $key a key identifying the cached value. This can be a simple string or
* a complex data structure consisting of factors representing the key.
* @return boolean true if a value exists in cache, false if the value is not in the cache or expired.
*/
public
function
exists
(
$key
)
{
$key
=
$this
->
buildKey
(
$key
);
$query
=
new
Query
;
$query
->
select
(
array
(
'COUNT(*)'
))
->
from
(
$this
->
cacheTable
)
->
where
(
'[[id]] = :id AND ([[expire]] = 0 OR [[expire]] >'
.
time
()
.
')'
,
array
(
':id'
=>
$key
));
if
(
$this
->
db
->
enableQueryCache
)
{
// temporarily disable and re-enable query caching
$this
->
db
->
enableQueryCache
=
false
;
$result
=
$query
->
createCommand
(
$this
->
db
)
->
queryScalar
();
$this
->
db
->
enableQueryCache
=
true
;
}
else
{
$result
=
$query
->
createCommand
(
$this
->
db
)
->
queryScalar
();
}
return
$result
>
0
;
}
/**
* Retrieves a value from cache with a specified key.
* This is the implementation of the method declared in the parent class.
* @param string $key a unique key identifying the cached value
...
...
framework/yii/caching/FileCache.php
View file @
427c373b
...
...
@@ -59,6 +59,26 @@ class FileCache extends Cache
}
/**
* Checks whether a specified key exists in the cache.
* This can be faster than getting the value from the cache if the data is big.
* Note that this method does not check whether the dependency associated
* with the cached data, if there is any, has changed. So a call to [[get]]
* may return false while exists returns true.
* @param mixed $key a key identifying the cached value. This can be a simple string or
* a complex data structure consisting of factors representing the key.
* @return boolean true if a value exists in cache, false if the value is not in the cache or expired.
*/
public
function
exists
(
$key
)
{
$cacheFile
=
$this
->
getCacheFile
(
$this
->
buildKey
(
$key
));
if
((
$time
=
@
filemtime
(
$cacheFile
))
>
time
())
{
return
true
;
}
else
{
return
false
;
}
}
/**
* Retrieves a value from cache with a specified key.
* This is the implementation of the method declared in the parent class.
* @param string $key a unique key identifying the cached value
...
...
framework/yii/caching/RedisCache.php
View file @
427c373b
...
...
@@ -104,6 +104,21 @@ class RedisCache extends Cache
}
/**
* Checks whether a specified key exists in the cache.
* This can be faster than getting the value from the cache if the data is big.
* Note that this method does not check whether the dependency associated
* with the cached data, if there is any, has changed. So a call to [[get]]
* may return false while exists returns true.
* @param mixed $key a key identifying the cached value. This can be a simple string or
* a complex data structure consisting of factors representing the key.
* @return boolean true if a value exists in cache, false if the value is not in the cache or expired.
*/
public
function
exists
(
$key
)
{
return
(
bool
)
$this
->
_connection
->
executeCommand
(
'EXISTS'
,
array
(
$this
->
buildKey
(
$key
)));
}
/**
* Retrieves a value from cache with a specified key.
* This is the implementation of the method declared in the parent class.
* @param string $key a unique key identifying the cached value
...
...
framework/yii/caching/WinCache.php
View file @
427c373b
...
...
@@ -8,7 +8,7 @@
namespace
yii\caching
;
/**
* WinCache provides
X
Cache caching in terms of an application component.
* WinCache provides
Windows
Cache caching in terms of an application component.
*
* To use this application component, the [WinCache PHP extension](http://www.iis.net/expand/wincacheforphp)
* must be loaded. Also note that "wincache.ucenabled" should be set to "On" in your php.ini file.
...
...
@@ -21,6 +21,22 @@ namespace yii\caching;
class
WinCache
extends
Cache
{
/**
* Checks whether a specified key exists in the cache.
* This can be faster than getting the value from the cache if the data is big.
* Note that this method does not check whether the dependency associated
* with the cached data, if there is any, has changed. So a call to [[get]]
* may return false while exists returns true.
* @param mixed $key a key identifying the cached value. This can be a simple string or
* a complex data structure consisting of factors representing the key.
* @return boolean true if a value exists in cache, false if the value is not in the cache or expired.
*/
public
function
exists
(
$key
)
{
$key
=
$this
->
buildKey
(
$key
);
return
wincache_ucache_exists
(
$key
);
}
/**
* Retrieves a value from cache with a specified key.
* This is the implementation of the method declared in the parent class.
* @param string $key a unique key identifying the cached value
...
...
framework/yii/caching/XCache.php
View file @
427c373b
...
...
@@ -22,6 +22,22 @@ namespace yii\caching;
class
XCache
extends
Cache
{
/**
* Checks whether a specified key exists in the cache.
* This can be faster than getting the value from the cache if the data is big.
* Note that this method does not check whether the dependency associated
* with the cached data, if there is any, has changed. So a call to [[get]]
* may return false while exists returns true.
* @param mixed $key a key identifying the cached value. This can be a simple string or
* a complex data structure consisting of factors representing the key.
* @return boolean true if a value exists in cache, false if the value is not in the cache or expired.
*/
public
function
exists
(
$key
)
{
$key
=
$this
->
buildKey
(
$key
);
return
xcache_isset
(
$key
);
}
/**
* Retrieves a value from cache with a specified key.
* This is the implementation of the method declared in the parent class.
* @param string $key a unique key identifying the cached value
...
...
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