Documentation Best Practices Options Size Limit (1MB)

Options Size Limit (1MB)

On, options are cached in memory to avoid database lookups, which speed things up. This is only effective if the cached object is kept small. Once the object reaches a certain limit (1MB) it will no longer cache and requests are sent to the database servers, which, depending on the traffic of the site, can cause a flood of requests and have a severe impact on performance.

Here are several guidelines you should keep in mind when working with options as storage containers.

  • Be sure the sum of all data you store in options (get_option(), etc.) is less than 400 KB at most. Options are meant for settings and plugin options. If you need to store bigger HTML fragments, consider using a custom post type or the wp-large-options plugin.
  • Each WP_Cache object can be no larger than 1MB or it will fail to cache. Where applicable and necessary, store items in individual cache objects rather than a single large cache object in order to avoid potentially hitting the limit.
  • Always store only what is really necessary in options. For example: If you need only the post_id, title or link of a post, don’t store the full post object.
  • Make sure your data is sanitized and validated.
  • Check that the data is not escaped twice. Double escaping data, especially if it is automatically filled, can cause the values to grow out of control.
  • Never write options from the front-end. Write operations caused by front-end functionality are generally a bad idea and will slow down your site.

Documentation is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.