# Manage media cache Media cache is a read-through caching mechanism for video-on-demand (VOD) streaming with Wowza Streaming Engineā„¢ [media server software](https://www.wowza.com/products/streaming-engine). Media cache lets you upload and manage content through a centralized location so that you can scale without adding hardware, implementing a content management system, taxing bandwidth and network resources, or increasing latency. You can use the Wowza Streaming Engine REST API to control and manage the media cache system. > **Notes:** - Wowza Streaming Engine 4.5.0 or later is required. - PHP examples for the tasks in this article are available in the **tests** folder of the [PHP REST Library for Wowza Streaming Engine on GitHub](https://github.com/WowzaMediaSystems/wse-rest-library-php). ## Get the current Media Cache configuration View the current Media Cache configuration in a local instance of Wowza Streaming Engine: > **Note:** You will replace {serverName} with the name of your server. ```bash curl -X GET \ -H 'Accept:application/json; charset=utf-8' \ -H 'Content-Type:application/json; charset=utf-8' \ http://127.0.0.1:8087/v3/servers/{serverName}/mediacache ``` The command should return a response that looks something like this: ```json { "version": "1489534580000", "serverName": "serverName", "writerThreadPoolSize": "${com.wowza.wms.TuningAuto}", "writerThreadPoolSizeAutoValue": "8", "readAheadThreadPoolSize": "${com.wowza.wms.TuningAuto}", "readAheadThreadPoolSizeAutoValue": "8", "maxPendingWriteRequestSize": "${com.wowza.wms.TuningAuto}", "maxPendingWriteRequestSizeAutoValue": "167772160", "maxPendingReadAheadRequestSize": "${com.wowza.wms.TuningAuto}", "maxPendingReadAheadRequestSizeAutoValue": "83886080", "stores": [{ "storeName": "default", "description": "Default Store", "path": "${com.wowza.wms.context.ServerConfigHome}/mediacache", "maxSize": "10G", "writeRate": "16M", "writeRateMaxBucketSize": "64M" }], "sources": [{ "sourceName": "dvrorigin", "type": "HTTP", "description": "Default DVR source", "basePath": "http://", "prefix": "dvrorigin/", "minTimeToLive": 14400000, "maxTimeToLive": 28800000, "isAmazonS3": false, "s3BucketNameInDomain": false, "awsAccessKeyId": "", "awsSecretAccessKey": "", "isPassThru": false, "baseClass": "com.wowza.wms.mediacache.impl.MediaCacheItemHTTPImpl", "httpReaderFactoryClass": "", "azureAccountName": "", "azureContainerName": "", "azureAccountKey": "", "googleServiceID": "", "googleServiceKey": "", "googleServicePrivateKeyFile": "", "googleServicePrivateKeyPassword": "", "googleEncMethod": "" }] } ``` ## Create a Media Cache configuration Create a Media Cache store in your Wowza Streaming Engine instance: > **Note:** You will name your store where {storeName} is shown. ```bash curl -X POST \ -H 'Accept:application/json; charset=utf-8' \ -H 'Content-type:application/json; charset=utf-8' \ http://127.0.0.1:8087/v3/servers/{serverName}/mediacache/stores/{storeName} \ -d '{ "path": "${com.wowza.wms.context.ServerConfigHome}/biggerStore2", "writeRate": "16M", "description": "", "storeName": "storeName", "maxSize": "3920G", "writeRateMaxBucketSize": "64M" }' ``` The command should return a response that looks something like this: ```json { "success": true, "message": "Saved", "data": null } ``` After restarting Wowza Streaming Engine to apply the configuration change, you can see the updated configuration in the Wowza Streaming Engine instance's **MediaCache.xml** file. ## Add a Media Cache source A Media Cache configuration can have multiple sources. A Media Cache *source* defines the type of content and the location of the content that's available to the Wowza Streaming Engine server. The location might be a local or networked disk, an Amazon S3 bucket, Google Cloud Storage, or a Microsoft Azure Blob storage account. > **Note:** You will name your source where {sourceName} is shown. ```bash curl -X POST \ -H 'Accept:application/json; charset=utf-8' \ -H 'Content-type:application/json; charset=utf-8' \ http://127.0.0.1:8087/v3/servers/{serverName}/mediacache/sources/{sourceName} \ -d '{ "readerClass": "", "isPassThru": false, "minTimeToLive": 14400000, "maxTimeToLive": 28800000, "prefix": "http/", "serverName": "", "description": "", "basePath": "http://192.168.1.1/", "baseClass": "com.wowza.wms.mediacache.impl.MediaCacheItemHTTPImpl", "type": "HTTP", "isAmazonS3": false, "s3BucketNameInDomain": false }' ``` The command should return a response that looks something like this: ```json { "success": true, "message": "Saved", "data": null } ``` After restarting Wowza Streaming Engine to apply the configuration change, you can see the new source in the `` section of the Wowza Streaming Engine instance's **MediaCache.xml** file: ```xml sourceName HTTP http://192.168.1.1/ http/ com.wowza.wms.mediacache.impl.MediaCacheItemHTTPImpl 1M 28800000 14400000 true 30 false ``` ## Specify Media Cache source properties Fine-tune a Media Cache source by specifying properties for it. For a list of Media Cache source properties, see [Wowza Streaming Engine MediaCache.xml configuration reference](https://www.wowza.com/docs/wowza-streaming-engine-mediacachexml-configuration-reference) and [Configure source properties for Wowza Streaming Engine Media Cache](https://www.wowza.com/docs/configure-media-cache-properties). Add the *httpConnectionTimeout* property to the Media Cache source *Source2*: ```bash curl -X POST \ -H 'Accept:application/json; charset=utf-8' \ -H 'Content-Type:application/json; charset=utf-8' \ http://127.0.0.1:8087/v3/servers/{serverName}/mediacache/sources/Source2/adv \ -d '{ "advancedSettings": [{ "enabled": true, "canRemove": true, "name": "httpConnectionTimeout", "value": "12000", "defaultValue": "6000", "type": "Integer", "sectionName": "Source2", "section": "/Root/MediaCacheSources/MediaCacheSource[Name='{sourceName}']", "documented": true }] }' ``` The command should return a response that looks something like this: ```json { "success": true, "message": "Saved", "data": null } ``` After restarting Wowza Streaming Engine to apply the configuration change, you can see the new **httpConnectionTimeout** property for **Source2** in the `` section of the Wowza Streaming Engine instance's **MediaCache.xml** file: ```xml Source2 HTTP http://192.168.1.1/ http/ com.wowza.wms.mediacache.impl.MediaCacheItemHTTPImpl 1M 28800000 14400000 true 30 false httpConnectionTimeout 12000 HTTP ``` ## Add a Media Cache store A Media Cache *store* defines where the content from the Media Cache source is cached by the Wowza Streaming Engine instance. > **Note:** You will name your store where {storeName} is shown. ```bash curl -X POST \ -H 'Accept:application/json; charset=utf-8' \ -H 'Content-Type:application/json; charset=utf-8' \ http://10.0.0.34:8087/v3/servers/{serverName}/mediacache/stores/{storeName} \ -d '{ "path": "/partition/large", "writeRate": "16M", "serverName": "Store2", "description": "", "storeName": "Store2", "maxSize": "500G", "writeRateMaxBucketSize": "64M" }' ``` The command should return a response that looks something like this: ```json { "success": true, "message": "Saved", "data": null } ``` After restarting Wowza Streaming Engine to apply the configuration change, you can see the new store in the `` section of the Wowza Streaming Engine instance's **MediaCache.xml** file: ```xml Store2 /partition/large 500G 16M 64M ``` ## Specify Media Cache store properties Fine-tune a Media Cache store by specifying properties for it. For a list of Media Cache store properties, see [Wowza Streaming Engine MediaCache.xml configuration reference](https://www.wowza.com/docs/wowza-streaming-engine-mediacachexml-configuration-reference). Add the **level1FolderCount** property to the Media Cache store *Store2*: ```bash curl -X POST \ -H 'Accept:application/json; charset=utf-8' \ -H 'Content-type:application/json; charset=utf-8' \ http://10.0.0.34:8087/v2/servers/{serverName}/mediacache/stores/Store2/adv \ -d '{ "advancedSettings": [{ "name": "level1FolderCount", "sectionName": "MediaCacheStore/Store2", "section": "/Root/MediaCacheStores/MediaCacheStore[Name='{storeName}']", "type": "Integer", "enabled": true, "value": "24", "documented": true }] }' ``` The command should return a response that looks something like this: ```json { "success": true, "message": "Saved", "data": null } ``` After restarting Wowza Streaming Engine to apply the configuration change, you can see the new **level1FolderCount** property for **Store2** in the `` section of the Wowza Streaming Engine instance's **MediaCache.xml** file: ```xml Store2 /partition/large 500G 16M 64M 24 ``` ## Get a list of Media Cache store assets View a detailed list of Media Cache stores (also called store assets, items, or files) for the default server of a local Wowza Streaming Engine instance: ```bash curl -X GET \ -H 'Accept:application/json; charset=utf-8' \ -H 'Content-Type:application/json; charset=utf-8' \ http://127.0.0.1:8087/v2/servers/{serverName}/vhosts/{vhostName}/mediacache/stores ``` The command should return a response that looks something like this: ```json { "serverName": "serverName", "mediacacheitemlist": [{ "itemname": "http/asset1.mp4", "itemlength": 75190106, "itemmaxtimetolive": 0, "itemmintimetolive": 0, "itemlastrelease": 1454022369252, "itemsourcename": "HTTP" }, { "itemname": "http/asset2.mp4", "itemlength": 75230106, "itemmaxtimetolive": 0, "itemmintimetolive": 0, "itemlastrelease": 1454022369450, "itemsourcename": "HTTP" }] } ``` ## Remove a Media Cache store asset Remove a store asset (*asset2.mp4*) that's not in use (option 1): ```bash curl -X PUT \ -H 'Accept:application/json; charset=utf-8' \ -H 'Content-Type:application/json; charset=utf-8' \ "http://127.0.0.1:8087/v2/servers/{serverName}/vhosts/{vhostName}/mediacache/stores/actions/flushItemFromCache?filename=http/asset2.mp4" ``` Remove a store asset (*asset2.mp4*) that's not in use from the application *vodedge* (option 2): ```bash curl -X PUT \ -H 'Accept:application/json; charset=utf-8' \ -H 'Content-Type:application/json; charset=utf-8' \ "http://127.0.0.1:8087/v2/servers/{serverName}/vhosts/{vhostName}/applications/vodedge/instances/{instanceName}/mediacache/stores/actions/flushStreamNameFromCache?filename=http/asset2.mp4" ``` Both commands should return a response that looks something like this: ```json { "success": true, "message": "Added http/sample.mp4 to flush list", "data": null } ``` Remove a store asset (*asset2.mp4*) that's in use: ```bash curl -X PUT \ -H 'Accept:application/json; charset=utf-8' \ -H 'Content-Type:application/json; charset=utf-8' \ "http://127.0.0.1:8087/v2/servers/{serverName}/vhosts/{vhostName}/mediacache/stores/actions/flushAndForceItemFromCache?filename=http/asset2.mp4" ``` Remove a store asset (*asset2.mp4*) that's in use by the *vodedge* application: ```bash curl -X PUT \ -H 'Accept:application/json; charset=utf-8' \ -H 'Content-Type:application/json; charset=utf-8' \ "http://127.0.0.1:8087/v2/servers/{serverName}/vhosts/{vhostName}/applications/vodedge/instances/{instanceName}/mediacache/stores/actions/flushAndForceStreamNameFromCache?filename=http/asset2.mp4" ``` Both commands should return a response that looks something like this: ```json { "success": true, "message": "Forcing http/asset2.mp4 to flush immediately", "data": null } ``` ## More resources - [Scale video-on-demand streaming with Wowza Streaming Engine Media Cache](https://www.wowza.com/docs/how-to-scale-video-on-demand-streaming-with-media-cache)