Due to its utility of returning a Faker instance that's ready to work, faker_create() could potentially be called many times during a single request from different methods.
I recommend static caching the result of faker_create() and returning the cached object if it's already been loaded.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | faker-static_cache-2203671-2.patch | 463 bytes | jrbeeman |
| #1 | faker-static_cache-2203671-1.patch | 547 bytes | jrbeeman |
Comments
Comment #1
jrbeemanFirst swing at a patch. I've been using this patch successfully on a project that needs to use the Faker library, but isn't utilizing devel_generate. It appears to be working as expected.
Comment #2
jrbeemanThe previous implementation was too complex. This new patch simplifies the static cache, removing the drupal_static() call seeing as there's no need for other modules to hook into this static cache.
Comment #4
baikho commentedNice, this also helps the usage of
unique()modifiers. See https://github.com/fzaninotto/Faker#modifiers