#Storing collections in the Service Container

2 messages · Page 1 of 1 (latest)

soft cape
#

I have a multi-tenant app where i refer to some collections frequently during a request's lifecycle, we're using redis but to reduce hits on redis i though i can save the collections as a key => value pair in the container using app()->scoped('key', fn() => $collection). Is this a code smell?

balmy fern
#

Hard to say without knowing what the collection contains. Generally it would probably be better to bind a class that manages the data in stead of a generic collection. That gives you type safety, editor completions and better static analysis.