diff --git a/docs/development/legacy/libraries/cache.md b/docs/development/legacy/libraries/cache.md index 21b76b067..0eb548ffd 100755 --- a/docs/development/legacy/libraries/cache.md +++ b/docs/development/legacy/libraries/cache.md @@ -15,9 +15,9 @@ lang: php [TOC] -ExpressionEngine's Cache Class gives developers easy ways to cache data (strings, arrays, objects) in a key-value store. The storage driver can be either file-based or memory-based. More about supported drivers and configuration can be found under [Data Caching and Performance](optimization/caching.md#caching-drivers). +ExpressionEngine's Cache Class gives developers easy ways to cache data (strings, arrays, objects) in a key-value store. The storage driver can be file-based, database-backed, or memory-based. More about supported drivers and configuration can be found under [Data Caching and Performance](optimization/caching.md#caching-drivers). -Unlike the [Session Cache](development/legacy/libraries/session.md#cache-access), items stored using the Cache class can persist across multiple page loads because cache items are either stored on disk or in a memory-based cache store not dependent on ExpressionEngine. +Unlike the [Session Cache](development/legacy/libraries/session.md#cache-access), items stored using the Cache class can persist across multiple page loads because cache items are stored on disk, in the database, or in a memory-based cache store not dependent on ExpressionEngine. It's highly recommended you use the Cache Class when possible instead of manually writing to a cache directory so that cache items can be easily managed and seamlessly moved to a memory-based cache store so those with high traffic or network file systems can take advantage of the speed and versatility a memory-based cache offers and not be bogged down by file locks and I/O limitations on the disk. @@ -149,3 +149,7 @@ Returns metadata about a particular item in the cache: Checks to see if appropriate extensions and resources are available for a driver to determine if it is usable for caching: ee()->cache->memcached->is_supported(); + +You can also check database driver support (it returns `FALSE` if the cache table is unavailable): + + ee()->cache->database->is_supported(); diff --git a/docs/development/legacy/libraries/output.md b/docs/development/legacy/libraries/output.md index f2b5e5aac..4b121b38a 100755 --- a/docs/development/legacy/libraries/output.md +++ b/docs/development/legacy/libraries/output.md @@ -163,11 +163,13 @@ NOTE: **Note:** Calling this method manually without aborting script execution w | Parameter | Type | Description | | --------- | -------- | -------------------- | -| \$msg | `Array` | Object to be sent to the client. | -| \$error | `Bool|Int` | HTTP status code. If `false`, status code is `200`. If `true`, status code is 500 | +| \$msg | `Mixed` | Value to be encoded and sent to the client. | +| \$statusCode | `Bool|Int` | HTTP status code. If `false`, status code is `200`. If `true`, status code is `500`. | | Returns | `Void` | void | -Calling this method encode the given `$msg` parameter and will set the header `Content-Type: application/json`. +Calling this method encodes the given `$msg` parameter and sets the header `Content-Type: application/json`. + +Any headers previously set with `set_header()` are also sent with the AJAX response. Example: @@ -177,11 +179,11 @@ Example: ); ee()->output->send_ajax_response($output); -With status code (401): +With status code (`401`): -``` +```php $output = array( - 'sucess' => 'false', + 'success' => false, 'message' => 'not allowed', ); ee()->output->send_ajax_response($output, 401); @@ -189,12 +191,21 @@ ee()->output->send_ajax_response($output, 401); As error with standard 500 error code: -``` +```php $output = array( - 'sucess' => 'false', + 'success' => false, 'message' => 'not allowed', ); ee()->output->send_ajax_response($output, true); +``` + +With a custom response header: + +```php +ee()->output + ->set_header('X-Example: value') + ->send_ajax_response(['success' => true], 200); +``` ### `show_message($data, $xhtml = true, $redirect_url = false, $template_name = 'generic')` @@ -269,4 +280,4 @@ appropriate template. | Returns | `Void` | void | This function builds upon `show_form_error()` with the additional ability to provide aliases for input names so -that variable names used in inline error handling can be more meaningful i.e. `field_name` instead of `field_id_1`. \ No newline at end of file +that variable names used in inline error handling can be more meaningful i.e. `field_name` instead of `field_id_1`. diff --git a/docs/general/system-configuration-overrides.md b/docs/general/system-configuration-overrides.md index 9bfba3cdc..c844a6663 100755 --- a/docs/general/system-configuration-overrides.md +++ b/docs/general/system-configuration-overrides.md @@ -511,7 +511,7 @@ Specify a different [caching driver](optimization/caching.md#caching-drivers) to | Values | Description | | --------- | -------------------------------------------------- | | file | File driver, /system/user/cache/ (default) | -| database | Database driver, uses the DB for caching | +| database | Database driver, stores cache in `exp_cache` | | memcached | Memcached driver, configured with memcached config | | redis | Redis driver, configured with redis config | | dummy | Dummy driver, will not cache | @@ -520,6 +520,10 @@ Example Usage: $config['cache_driver'] = 'memcached'; +Database-backed caching is also available: + + $config['cache_driver'] = 'database'; + ## `cache_driver_backup` Specify a backup [caching driver](optimization/caching.md#caching-drivers) to use in case the one specified in [cache_driver](#cache_driver) isn't available. Same values accepted and same default as [cache_driver](#cache_driver). diff --git a/docs/optimization/caching.md b/docs/optimization/caching.md index 947863b33..62ecdb606 100755 --- a/docs/optimization/caching.md +++ b/docs/optimization/caching.md @@ -89,9 +89,11 @@ You can also use disable="category_fields" in the [channel categories](channels/ **Control Panel Location:** `Settings --> Debugging & Output` -By default, ExpressionEngine uses a file-based caching driver, meaning cached items are written to disk. This is the most-compatible option for all servers and works well in most cases. However, the traffic on your site may reach a point where the file-based caching becomes a bottleneck due to disk I/O, or may cause issues in some Network File System instances, in which case you may want to use a memory-based caching driver. +By default, ExpressionEngine uses a file-based caching driver, meaning cached items are written to disk. This is the most-compatible option for all servers and works well in most cases. However, the traffic on your site may reach a point where file-based caching becomes a bottleneck due to disk I/O, or may cause issues in some Network File System instances. -ExpressionEngine currently supports Memcached and Redis for memory-based caching. You can set which driver is being used in the control panel or via the [cache_driver](general/system-configuration-overrides.md#cache_driver) config override. [Memcached](general/system-configuration-overrides.md#memcached) and [Redis](general/system-configuration-overrides.md#redis) server information can also be set in `config.php`, otherwise ExpressionEngine will try to connect to the default respective ports on localhost. +ExpressionEngine also supports database, Memcached, and Redis caching drivers. You can set which driver is being used in the control panel or via the [cache_driver](general/system-configuration-overrides.md#cache_driver) config override. [Memcached](general/system-configuration-overrides.md#memcached) and [Redis](general/system-configuration-overrides.md#redis) server information can also be set in `config.php`, otherwise ExpressionEngine will try to connect to the default respective ports on localhost. + +The database driver stores cache rows in `exp_cache`, which can reduce filesystem I/O but adds read/write load to your database server. For higher-throughput workloads, Memcached or Redis are generally better choices. You can also set caching to Database, which uses the same database for cache data as the rest of your site data. There are pros and cons to this approach. If you can't easily use memcached or redis, database caching can be another way to use RAM-based caching; on the other hand, this can create additional database read and write calls that can be slower than file or memory-based caching choices. Database works well in load balanced environments, where memcache and redis are more difficult to work with due to the difficulty in synchronizing across servers. Test out database caching performance and compare your specific results before committing to it.