Skip to content

Commit

Permalink
fix cache speed issue
Browse files Browse the repository at this point in the history
  • Loading branch information
JRSaunders committed Mar 8, 2022
1 parent 015b415 commit 591fee6
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/DB/ShardCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,33 @@ public static function execute(
return $shardDb->__execute( $preStatement, $useNewConnection, $rollbacks );
}
$key = $preStatement->getHashKey();
if ( $remove && $preStatement->getUuid() ) {
$shardDb->getPdoCache()->clean( $preStatement->getUuid() );
if ( $remove ) {
if ( $preStatement->getUuid() ) {
$shardDb->getPdoCache()->clean( $preStatement->getUuid() );
if ( $preStatement->isFreshDataOnly() ) {
$shardDb->getPdoCache()->cleanAllMatching( $preStatement->getUuid() );
}
} else {
$shardDb->getPdoCache()->clean( $key );
}
} elseif ( ! $preStatement->isFreshDataOnly() && ! $useNewConnection ) {
$cacheRead = $shardDb->getPdoCache()->read( $key );
if ( $cacheRead instanceof ResultsInterface && $cacheRead->isSuccessful() ) {
return $cacheRead;
if ( $preStatement->getUuid() ) {
$cacheRead = $shardDb->getPdoCache()->read( $preStatement->getUuid() );
if ( $cacheRead instanceof ResultsInterface && $cacheRead->isSuccessful() ) {
return $cacheRead;
}
} else {
$cacheRead = $shardDb->getPdoCache()->read( $key );
if ( $cacheRead instanceof ResultsInterface && $cacheRead->isSuccessful() ) {
return $cacheRead;
}
}
}
$returnValue = $shardDb->__execute( $preStatement, $useNewConnection, $rollbacks );
if ( $returnValue instanceof ResultsInterface && $preStatement->isSelectQuery() ) {
if ( $returnValue instanceof ResultsInterface && $preStatement->isSelectQuery() && ! $preStatement->getUuid() ) {
$shardDb->getPdoCache()->write( $key, $returnValue );
} else if ( $returnValue instanceof ResultsInterface && $preStatement->isSelectQuery() && $preStatement->getUuid() ) {
$shardDb->getPdoCache()->write( $preStatement->getUuid(), $returnValue );
}

return $returnValue;
Expand Down

0 comments on commit 591fee6

Please sign in to comment.