Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Configuration to disable events on Cache Repository #51032

Merged
merged 3 commits into from
Apr 12, 2024

Conversation

serpentblade
Copy link
Contributor

@serpentblade serpentblade commented Apr 12, 2024

This change allows caches to be defined without auto-registering events dispatcher.

On in-memory caches like array or apc, the overhead of triggering events results in an 80%+ overhead for basic cache operations. This change allows a config value on any cache definition to disable events for that particular Repository.

Benefit:
In some circumstances it is helpful to use an in-memory cache like array or apc, however in operations that use a lot of cache calls the overhead starts to dramatically impact performance. Being able to define a cache without events allows for the conveniences of the caching API while minimizing the overhead to the API implementation and not the events side-effects.

Usage:
Adding 'with_events' => false to any cache stores configuration will prevent the automatic registration of the events dispatcher. For example, the following changes the 'array' store to not register events:

[
    ...
    'stores' => [
        'array' => [
            'driver' => 'array',
            'serialize' => false,
            'with_events' => false,
        ],
   ]
]

Backwards Compatibility Concerns:
I've implemented this new setting to default to true when the setting isn't defined on the config, so it has no backwards compatibility concerns.

Tests:
Added test for CacheManager to handle this new setting and test the previous functionality where no setting is provided.

Allow caches to be defined without auto-registering events dispatcher.

On in-memory caches like array or apc, the overhead of triggering events results in 80%+ overhead in basic cache operations.  This change allows adding a config value to disable events for that particular Cache Repository.
@taylorotwell taylorotwell merged commit c1bec87 into laravel:11.x Apr 12, 2024
25 of 28 checks passed
@serpentblade serpentblade deleted the feature/optional-cache-events branch April 12, 2024 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants