Skip to content

Improving mutator cache in Eloquent #9276

Closed
@reshadman

Description

@reshadman

Currently the eloquent model class contains a cache strategy for getters which first fetches all class methods and runs a loop on them filtering them by a regular expression.
This occurs only once per unique eloquent final object.
The getter cache container is only filled up with the processed snake case attribute key.

Each time a new model class is created for first time a loop with 50 to 100 iterations with processing a regular expression is run.

Wouldn't it be cool to have something like php artisan eloquent:cache for this ?

Also the method name can be saved in the mutator cache container, which prevents further string processing (for fetching method name from a given attribute) as both attribute name and the getter method name exist in the cache array.

$mutatedAttributes[$method] = lcfirst($matches[1]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions