Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,9 @@ function set( $id, $data, $group = 'default', $expire = 0 ) {
];

if ( in_array( $group, $this->no_mc_groups ) ) {
$this->group_ops_stats( 'set_local', $key, $group, null, null );
$this->group_ops_stats( 'set_local', $key, $group, null, null );
// If using a non persistent group it will never be in memcache but will be found in our local cache so set found to true.
$this->cache[ $key ]['found'] = true;

return true;
}
Expand Down
31 changes: 27 additions & 4 deletions tests/test-object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -828,26 +828,49 @@ public function test_set_can_be_performed_per_group(): void {
}

public function test_set_updated_found_status_with_memcache_result(): void {
// Need this to ensure cache is set witout going to memcache.
// Need this to ensure cache is set witout going to memcache and using non persistent groups.
$group = 'do-not-persist-me';
$this->object_cache->add_non_persistent_groups( [ $group ] );

$this->object_cache->set( 'foo', 'data', $group );
$key = $this->object_cache->key( 'foo', $group );

// Check it's false until we use memcache.
$this->assertFalse( $this->object_cache->cache[ $key ][ 'found' ] );
// Check it's true even though we're not using memcache.
$this->assertTrue( $this->object_cache->cache[ $key ][ 'found' ] );

// Remove non-persistent group.
$this->object_cache->no_mc_groups = [];

// Re-set.
$this->object_cache->set( 'foo', 'data', $group );

// Cached found value should now be true.
// Cached found value should still be true.
$this->assertTrue( $this->object_cache->cache[ $key ][ 'found' ] );
}

/**
* @see https://github.com/Automattic/wp-memcached/issues/61
*/
public function test_found_is_set_when_using_non_persistent_groups(): void {
/**
* wp> wp_cache_add_non_persistent_groups( [ 'example' ] );
* NULL
* wp> wp_cache_set( 'example', 'example', 'example' );
* bool(true)
* wp> wp_cache_get( 'example', 'example', false, $found );
* string(7) "example"
* wp> $found
* bool(false)
*/

$groups = [ 'example' ];
$this->object_cache->add_non_persistent_groups( $groups );
$this->object_cache->set( 'example', 'example', 'example' );
$this->object_cache->get( 'example', 'example', false, $found );

$this->assertTrue( $found );
}

// Tests for switch_to_blog.

public function test_switch_to_blog_sets_blog_prefix_depending_on_multi_site_status(): void {
Expand Down