laravel / pennant

A simple, lightweight library for managing feature flags.
https://laravel.com/docs/pennant
MIT License
474 stars 48 forks source link

[1.x] Ensure cache holds serialized values only #83

Closed timacdonald closed 8 months ago

timacdonald commented 8 months ago

fixes https://github.com/laravel/pennant/issues/82

The cache is currently holding onto scope object, which is a potential memory issue as all scope will now stay in memory until the end of the request.

It also means that the cache behaves unexpectedly for eloquent models when different instances of the same record are used, e.g.,

Feature::for(User::find(123))->activate('foo');

Feature::for(User::find(123))->activate('foo');

This fixes the memory issue and model reference issues by making sure the scope is serialized before it enters the cache.