spatie / sheets

Store & retrieve your static content in plain text files
https://spatie.be/open-source
MIT License
273 stars 21 forks source link

keep sheet instance references during runtime #46

Closed Gummibeer closed 4 years ago

Gummibeer commented 4 years ago

If I have larger collections and load this collection multiple times during a request Sheets::collection('large')->all() the memory can quickly explode. A solution would be to use the already present unique string key for a single sheet in a poor man cache to keep the same sheet object reference for the whole request/runtime.

if (! isset($cache[$collectionName][$sheetName])) {
   $cache[$collectionName][$sheetName] = new Sheet(...);
}

return $cache[$collectionName][$sheetName];

This should be a non breaking change as long as the sheet file isn't changed on runtime. In this case it should be possible to invalidate a cache entry.

The cache logic should be placed in the repository which loads the file content - in this case #45 would provide a solution outside the package. But I would like to provide this as a trait in the package. This way it would be reusable for all custom repositories with a single method call.

spatie-bot commented 4 years ago

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.

Gummibeer commented 4 years ago

This issue isn't resolved.