Media Cache is a read-through caching mechanism for video-on-demand (VOD) streaming with Wowza Streaming Engine™ media server software. 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.
- Reference documentation for the Wowza Streaming Engine REST API is available by using OpenAPI (Swagger), which you can download and install locally. See Access reference documentation for the Wowza Streaming Engine REST API.
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.
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:
{ "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.
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:
{ "
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 an Microsoft Azure Blob storage account.
Note: You will name your source where {sourceName} is shown.
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:
{ "
success":
true, "
message":
"Saved", "
data":
null }
After restarting Wowza Streaming Engine to apply the configuration change, you can see the new source in the <MediaCacheSources> section of the Wowza Streaming Engine instance's MediaCache.xml file:
<MediaCacheSources> <MediaCacheSource> <Name>sourceName</Name> <Type>HTTP</Type> <Description></Description> <BasePath>http://192.168.1.1/BasePath> <Prefix>http/</Prefix> <BaseClass>com.wowza.wms.mediacache.impl.MediaCacheItemHTTPImpl</BaseClass> <ReaderClass></ReaderClass> <DefaultBlockSize>1M</DefaultBlockSize> <MaxTimeToLive>28800000</MaxTimeToLive> <MinTimeToLive>14400000</MinTimeToLive> <ReadAhead>true</ReadAhead> <ReadAheadThreshold>30</ReadAheadThreshold> <IsPassThru>false</IsPassThru> </MediaCacheSource> </MediaCacheSources>
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 and Configure source properties for Wowza Streaming Engine Media Cache.
Add the httpConnectionTimeout property to the Media Cache source Source2:
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:
{ "
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 <MediaCacheSources> section of the Wowza Streaming Engine instance’s MediaCache.xml file:
<MediaCacheSources> <MediaCacheSource> <Name>Source2</Name> <Type>HTTP</Type> <Description></Description> <BasePath>http://192.168.1.1/BasePath> <Prefix>http/</Prefix> <BaseClass>com.wowza.wms.mediacache.impl.MediaCacheItemHTTPImpl</BaseClass> <ReaderClass></ReaderClass> <DefaultBlockSize>1M</DefaultBlockSize> <MaxTimeToLive>28800000</MaxTimeToLive> <MinTimeToLive>14400000</MinTimeToLive> <ReadAhead>true</ReadAhead> <ReadAheadThreshold>30</ReadAheadThreshold> <IsPassThru>false</IsPassThru> <Properties> <Property> <Name>httpConnectionTimeout</Name> <Value>12000</Value> <Type>HTTP</Type> </Property> </Properties> </MediaCacheSource> </MediaCacheSources>
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.
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:
{ "
success":
true, "
message":
"Saved", "
data":
null }
After restarting Wowza Streaming Engine to apply the configuration change, you can see the new store in the <MediaCacheStores> section of the Wowza Streaming Engine instance's MediaCache.xml file:
<MediaCacheStores> <MediaCacheStore> <Name>Store2</Name> <Description></Description> <Path>/partition/large</Path> <MaxSize>500G</MaxSize> <WriteRate>16M</WriteRate> <WriteRateBucketSize>64M</WriteRateBucketSize> </MediaCacheStore> </MediaCacheStores>
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.
Add the level1FolderCount property to the Media Cache store Store2:
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:
{ "
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 <MediaCacheStores> section of the Wowza Streaming Engine instance’s MediaCache.xml file:
<MediaCacheStores> <MediaCacheStore> <Name>Store2</Name> <Description></Description> <Path>/partition/large</Path> <MaxSize>500G</MaxSize> <WriteRate>16M</WriteRate> <WriteRateBucketSize>64M</WriteRateBucketSize> <Level1FolderCount>24</Level1FolderCount> </MediaCacheStore> </MediaCacheStores>
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:
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:
{ "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):
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):
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:
{ "success":true, "message": "Added http/sample.mp4 to flush list", "data":null }
Remove a store asset (asset2.mp4) that's in use:
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:
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:
{ "success":true, "message":"Forcing http/asset2.mp4 to flush immediately", "data":null }