laravel / pennant

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

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

Closed timacdonald closed 10 months ago

timacdonald commented 10 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.