How to manage Media Cache by using the Wowza Streaming Engine REST API

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:

Contents


Get the current Media Cache configuration
Create a Media Cache configuration
Add a Media Cache source
Specity Media Cache source properties
Add a Media Cache store
Specify Media Cache store properties
Get a list of Media Cache store assets
Remove a Media Cache store asset
More resources

Get the current Media Cache configuration


View the current Media Cache configuration (the default Media Cache on the default server in this example) in a local instance of Wowza Streaming Engine:

curl  -X GET --header 'Accept:application/json; charset=utf-8' --header 'Content-Type:application/json; charset=utf-8' http://127.0.0.1:8087/v3/servers/_defaultServer_/mediacache

The command should return a response that looks something like this:

{
  "version": "1489534580000",
  "serverName": "_defaultServer_",
  "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:

curl  -X POST --header 'Accept:application/json; charset=utf-8' --header 'Content-type:application/json; charset=utf-8' http://127.0.0.1:8087/v3/servers/_defaultServer_/mediacache/stores/Store3 -d '
{
  "path": "${com.wowza.wms.context.ServerConfigHome}/biggerStore2",
  "writeRate": "16M",
  "description": "",
  "storeName": "StoreNew",
  "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.

Create a Media Cache source (Source2 in this example):

curl  -X POST --header 'Accept:application/json; charset=utf-8' --header 'Content-type:application/json; charset=utf-8' http://127.0.0.1:8087/v3/servers/_defaultServer_/mediacache/sources/Source2 -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>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>
  </MediaCacheSource>
</MediaCacheSources>

Specify Media Cache source properties


Fine-tune a Media Cache source by specifying properties for it. For a complete list of Media Cache source properties, see "Configure Media Cache source properties" and "Add custom Media Cache HTTP source properties" in the Wowza Media Cache User's Guide.

Add the httpConnectionTimeout property to the Media Cache source Source2:

curl  -X POST --header 'Accept:application/json; charset=utf-8' --header 'Content-Type:application/json; charset=utf-8' http://127.0.0.1:8087/v3/servers/_defaultServer_/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.

Create a Media Cache store (Store2 in this example):

curl  -X POST --header 'Accept:application/json; charset=utf-8' --header 'Content-Type:application/json; charset=utf-8' http://10.0.0.34:8087/v3/servers/_defaultServer_/mediacache/stores/Store2 -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 complete list of Media Cache store properties, see "Configure Media Cache store properties" in the Wowza Media Cache User's Guide.

Add the level1FolderCount property to the Media Cache store Store2:

curl  -X POST --header 'Accept:application/json; charset=utf-8' --header 'Content-type:application/json; charset=utf-8' http://10.0.0.34:8087/v2/servers/_defaultServer_/mediacache/stores/Store3/adv -d '
{ 
  "advancedSettings": [{
    "name": "level1FolderCount",
    "sectionName": "MediaCacheStore/Store3",
    "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 --header 'Accept:application/json; charset=utf-8' --header 'Content-Type:application/json; charset=utf-8' http://127.0.0.1:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/mediacache/stores

The command should return a response that looks something like this:

{
"serverName": "_defaultServer_",
  "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--header 'Accept:application/json; charset=utf-8' --header 'Content-Type:application/json; charset=utf-8' "http://127.0.0.1:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/mediacache/stores/actions/flushItemFromCache?filename=http/asset2.mp4"

Remove a store asset (asset2.mp4) that's not in use (option 2):

curl  -X PUT--header 'Accept:application/json; charset=utf-8' --header 'Content-Type:application/json; charset=utf-8' "http://127.0.0.1:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/vodedge/instances/_definst_/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--header 'Accept:application/json; charset=utf-8' --header 'Content-Type:application/json; charset=utf-8' "http://127.0.0.1:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/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--header 'Accept:application/json; charset=utf-8' --header 'Content-Type:application/json; charset=utf-8' "http://127.0.0.1:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/vodedge/instances/_definst_/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
}

More resources



If you're having problems or want to discuss this article, post in our forum.