Skip to content

Commit

Permalink
only delete redis cache when you have matches
Browse files Browse the repository at this point in the history
  • Loading branch information
JRSaunders committed Jul 20, 2020
1 parent f9c1b3c commit 572bedb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/PdoCacheMemcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public function scanAndClean( string $key ): array {
foreach ( $keys as $key ) {
$results[] = $this->read( $key );
}
$this->memcached->deleteMulti( $keys );
if ( $keys ) {
$this->memcached->deleteMulti( $keys );
}
}

return $results;
Expand All @@ -73,7 +75,7 @@ public function write( string $key, $data ): bool {
}
$this->setKeysArray( $key );

return (bool) $this->memcached->set( $this->prefixKey( $key), gzdeflate( serialize( $data ) ), $this->cacheTime );
return (bool) $this->memcached->set( $this->prefixKey( $key ), gzdeflate( serialize( $data ) ), $this->cacheTime );
}

/**
Expand All @@ -89,14 +91,14 @@ protected function setKeysArray( $key ) {
if ( $i == count( $keySplit ) ) {
$partKey .= $delimiter;
}
$existingKeys = $this->memcached->get( $this->prefixKey( $partKey ));
$existingKeys = $this->memcached->get( $this->prefixKey( $partKey ) );
if ( ! is_array( $existingKeys ) ) {
$existingKeys = [];
}

$existingKeys[] = $key;

$this->memcached->set( $this->prefixKey( $partKey), array_unique( $existingKeys ), $this->cacheTime );
$this->memcached->set( $this->prefixKey( $partKey ), array_unique( $existingKeys ), $this->cacheTime );
}
};
$splitKey( explode( '-', $key ), '-', $key );
Expand Down

0 comments on commit 572bedb

Please sign in to comment.