Skip to content

TimelineCache::forget() flushes the entire cache store #12

@ManukMinasyan

Description

@ManukMinasyan

Summary

TimelineCache::forget(Model $subject) (src/Timeline/TimelineCache.php) ignores the $subject argument and calls $this->store()->getStore()->flush() — wiping every cached value in the store, not just this subject's timeline entries.

public function forget(Model $subject): void
{
    unset($subject);
    $this->store()->getStore()->flush();
}

Impact

If the user's app shares the default cache store with sessions, application caches, etc., calling $person->forgetTimelineCache() clears all of those too.

Recommended fix

Replace with tagged-cache invalidation keyed on the keyFor() prefix, e.g.:

public function forget(Model $subject): void
{
    $prefix = sprintf(
        '%s:%s:%s:',
        config('activity-log.cache.key_prefix', 'activity-log'),
        str_replace('\\\\', '_', $subject::class),
        (string) $subject->getKey(),
    );

    // Use Cache::tags() if driver supports it, otherwise track keys per subject.
}

Tracked by docs spec

Finding A3 in the upcoming docs restructure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions