Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/27/2014 07:04:30 PM (10 years ago)
Author:
r-a-y
Message:

Notifications: Invalidate cache when a notification is updated.

Object caching was added to the notifications component in r7813.
However, the cached item was not invalidated whenever a notification
is updated (either by using one of the marked as read functions or via
using the BP_Notifications_Notification::update() method).

This commit invalidates the cache directly in the update() class
method and adds a unit test.

See #5377

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/testcases/notifications/functions.php

    r8102 r8176  
    9191        $this->assertNotEmpty( bp_notifications_add_notification( $args ) );
    9292    }
     93
     94    /**
     95     * @group bp_notifications_get_unread_notification_count
     96     * @group cache
     97     */
     98    public function test_bp_notifications_get_unread_notification_count_cache() {
     99        $u1 = $this->create_user();
     100        $u2 = $this->create_user();
     101
     102        $n1 = $this->factory->notification->create( array(
     103            'component_name'    => 'messages',
     104            'component_action'  => 'new_message',
     105            'item_id'           => 99,
     106            'user_id'           => $u2,
     107            'secondary_item_id' => $u1,
     108            'is_new'            => true,
     109        ) );
     110
     111        // prime cache
     112        bp_notifications_get_unread_notification_count( $u2 );
     113
     114        // mark the created notification as read
     115        bp_notifications_mark_notifications_by_item_id( $u2, 99, 'messages', 'new_message', $u1 );
     116
     117        // now grab the updated notification count
     118        $n = bp_notifications_get_unread_notification_count( $u2 );
     119
     120        // assert
     121        $this->assertEquals( 0, $n );
     122    }
    93123}
Note: See TracChangeset for help on using the changeset viewer.