Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
e1ad90ba
Commit
e1ad90ba
authored
15 years ago
by
Dries Buytaert
Browse files
Options
Downloads
Patches
Plain Diff
- Patch
#575360
by dropcube: added API function to check if a cache bin is empty.
parent
b5cee8fe
Loading
Loading
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
includes/cache-install.inc
+4
-1
4 additions, 1 deletion
includes/cache-install.inc
includes/cache.inc
+36
-0
36 additions, 0 deletions
includes/cache.inc
modules/simpletest/tests/cache.test
+37
-0
37 additions, 0 deletions
modules/simpletest/tests/cache.test
with
77 additions
and
1 deletion
includes/cache-install.inc
+
4
−
1
View file @
e1ad90ba
...
@@ -28,5 +28,8 @@ function set($cid, $data, $expire = CACHE_PERMANENT, array $headers = NULL) {
...
@@ -28,5 +28,8 @@ function set($cid, $data, $expire = CACHE_PERMANENT, array $headers = NULL) {
function
clear
(
$cid
=
NULL
,
$wildcard
=
FALSE
)
{
function
clear
(
$cid
=
NULL
,
$wildcard
=
FALSE
)
{
}
}
function
isEmpty
()
{
return
TRUE
;
}
}
}
This diff is collapsed.
Click to expand it.
includes/cache.inc
+
36
−
0
View file @
e1ad90ba
...
@@ -167,6 +167,21 @@ function cache_clear_all($cid = NULL, $bin = NULL, $wildcard = FALSE) {
...
@@ -167,6 +167,21 @@ function cache_clear_all($cid = NULL, $bin = NULL, $wildcard = FALSE) {
return
_cache_get_object
(
$bin
)
->
clear
(
$cid
,
$wildcard
);
return
_cache_get_object
(
$bin
)
->
clear
(
$cid
,
$wildcard
);
}
}
/**
* Check if a cache bin is empty.
*
* A cache bin is considered empty if it does not contain any valid data for any
* cache ID.
*
* @param $bin
* The cache bin to check.
* @return
* TRUE if the cache bin specified is empty.
*/
function
cache_is_empty
(
$bin
)
{
return
_cache_get_object
(
$bin
)
->
isEmpty
();
}
/**
/**
* Interface for cache implementations.
* Interface for cache implementations.
*
*
...
@@ -260,6 +275,17 @@ function set($cid, $data, $expire = CACHE_PERMANENT, array $headers = NULL);
...
@@ -260,6 +275,17 @@ function set($cid, $data, $expire = CACHE_PERMANENT, array $headers = NULL);
* match. If '*' is given as $cid, the bin $bin will be emptied.
* match. If '*' is given as $cid, the bin $bin will be emptied.
*/
*/
function
clear
(
$cid
=
NULL
,
$wildcard
=
FALSE
);
function
clear
(
$cid
=
NULL
,
$wildcard
=
FALSE
);
/**
* Check if a cache bin is empty.
*
* A cache bin is considered empty if it does not contain any valid data for
* any cache ID.
*
* @return
* TRUE if the cache bin specified is empty.
*/
function
isEmpty
();
}
}
/**
/**
...
@@ -449,4 +475,14 @@ function clear($cid = NULL, $wildcard = FALSE) {
...
@@ -449,4 +475,14 @@ function clear($cid = NULL, $wildcard = FALSE) {
}
}
}
}
}
}
function
isEmpty
()
{
$this
->
garbageCollection
();
$query
=
db_select
(
$this
->
bin
);
$query
->
addExpression
(
'1'
);
$result
=
$query
->
range
(
0
,
1
)
->
execute
()
->
fetchField
();
return
empty
(
$result
);
}
}
}
This diff is collapsed.
Click to expand it.
modules/simpletest/tests/cache.test
+
37
−
0
View file @
e1ad90ba
...
@@ -312,3 +312,40 @@ class CacheClearCase extends CacheTestCase {
...
@@ -312,3 +312,40 @@ class CacheClearCase extends CacheTestCase {
t
(
'All cache entries removed when the array exceeded the cache clear threshold.'
));
t
(
'All cache entries removed when the array exceeded the cache clear threshold.'
));
}
}
}
}
/**
* Test cache_is_empty() function.
*/
class
CacheIsEmptyCase
extends
CacheTestCase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Cache emptiness test'
,
'description'
=>
'Check if a cache bin is empty after performing clear operations.'
,
'group'
=>
'Cache'
);
}
function
setUp
()
{
$this
->
default_bin
=
'cache_page'
;
$this
->
default_value
=
$this
->
randomName
(
10
);
parent
::
setUp
();
}
/**
* Test clearing using a cid.
*/
function
testIsEmpty
()
{
// Clear the cache bin.
cache_clear_all
(
'*'
,
$this
->
default_bin
);
$this
->
assertTrue
(
cache_is_empty
(
$this
->
default_bin
),
t
(
'The cache bin is empty'
));
// Add some data to the cache bin.
cache_set
(
$this
->
default_cid
,
$this
->
default_value
,
$this
->
default_bin
);
$this
->
assertCacheExists
(
t
(
'Cache was set.'
),
$this
->
default_value
,
$this
->
default_cid
);
$this
->
assertFalse
(
cache_is_empty
(
$this
->
default_bin
),
t
(
'The cache bin is not empty'
));
// Remove the cached data.
cache_clear_all
(
$this
->
default_cid
,
$this
->
default_bin
);
$this
->
assertCacheRemoved
(
t
(
'Cache was removed.'
),
$this
->
default_cid
);
$this
->
assertTrue
(
cache_is_empty
(
$this
->
default_bin
),
t
(
'The cache bin is empty'
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment