Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
justinfreeman (Agileware)
Core
Commits
51f193c5
Commit
51f193c5
authored
12 years ago
by
colemanw
Browse files
Options
Downloads
Plain Diff
Merge pull request #381 from totten/sqlgroup-prefetch
CRM-12321 - SqlGroupTest - Test prefetching more directly.
parents
c60bb823
20b015e1
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/Utils/Cache/SqlGroup.php
+4
-0
4 additions, 0 deletions
CRM/Utils/Cache/SqlGroup.php
tests/phpunit/CRM/Utils/Cache/SqlGroupTest.php
+15
-11
15 additions, 11 deletions
tests/phpunit/CRM/Utils/Cache/SqlGroupTest.php
with
19 additions
and
11 deletions
CRM/Utils/Cache/SqlGroup.php
+
4
−
0
View file @
51f193c5
...
...
@@ -96,6 +96,10 @@ class CRM_Utils_Cache_SqlGroup implements CRM_Utils_Cache_Interface {
return
$this
->
frontCache
[
$key
];
}
function
getFromFrontCache
(
$key
,
$default
=
NULL
)
{
return
CRM_Utils_Array
::
value
(
$key
,
$this
->
frontCache
,
$default
);
}
function
delete
(
$key
)
{
CRM_Core_BAO_Cache
::
deleteGroup
(
$this
->
group
,
$key
);
unset
(
$this
->
frontCache
[
$key
]);
...
...
This diff is collapsed.
Click to expand it.
tests/phpunit/CRM/Utils/Cache/SqlGroupTest.php
+
15
−
11
View file @
51f193c5
...
...
@@ -55,29 +55,33 @@ class CRM_Utils_Cache_SqlGroupTest extends CiviUnitTestCase {
}
/**
* Add item to one cache instance then read (
and
prefetch)
with
another
* Add item to one cache instance then read (
with or without
prefetch)
from
another
*/
function
testPrefetch
()
{
// 1. put data in cache
$a
=
new
CRM_Utils_Cache_SqlGroup
(
array
(
'group'
=>
'testPrefetch'
,
'prefetch'
=>
FALSE
,
));
$fooValue
=
array
(
'whiz'
=>
'bang'
,
'bar'
=>
4
);
$a
->
set
(
'foo'
,
$fooValue
);
$this
->
assertEquals
(
$a
->
get
(
'foo'
),
array
(
'whiz'
=>
'bang'
,
'bar'
=>
4
));
// 2. see what happens when prefetch is TRUE
$b
=
new
CRM_Utils_Cache_SqlGroup
(
array
(
'group'
=>
'testPrefetch'
,
'prefetch'
=>
TRUE
,
));
// assuming the values have been prefetched in $b, we can do a stale
// read -- i.e. change the underlying data table and then read the
// prefetched value from $b
$fooValue2
=
'muahahaha'
;
$a
->
set
(
'foo'
,
$fooValue2
);
$this
->
assertEquals
(
$b
->
get
(
'foo'
),
array
(
'whiz'
=>
'bang'
,
'bar'
=>
4
));
// ok, enough with the stale reading
$b
->
prefetch
();
$this
->
assertEquals
(
$b
->
get
(
'foo'
),
'muahahaha'
);
$this
->
assertEquals
(
$fooValue
,
$b
->
getFromFrontCache
(
'foo'
));
// should work b/c value was prefetched
$this
->
assertEquals
(
$fooValue
,
$b
->
get
(
'foo'
));
// should work b/c value was prefetched
// 3. see what happens when prefetch is FALSE
$c
=
new
CRM_Utils_Cache_SqlGroup
(
array
(
'group'
=>
'testPrefetch'
,
'prefetch'
=>
FALSE
,
));
$this
->
assertEquals
(
NULL
,
$c
->
getFromFrontCache
(
'foo'
));
// should be NULL b/c value was NOT prefetched
$this
->
assertEquals
(
$fooValue
,
$c
->
get
(
'foo'
));
// should work b/c value is fetched on demand
$this
->
assertEquals
(
$fooValue
,
$c
->
getFromFrontCache
(
'foo'
));
// should work b/c value was fetched on demand
}
}
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