Results 1 to 4 of 4

Thread: MediaCache , I wan to clear a specific media cache.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2013

    Default MediaCache , I wan to clear a specific media cache.


    I am using MediaCache plugin to serve VOD service.
    To purge, now, I am using the
    However, the problem is that the cached file is alive until the MediaCache.gc() is executed.
    Thus, between purging and the MediaCache.gc() execution, the new connection can still use old cached file.
    As for the Sanjose streaming, the session.rejectSession() could not destroy the stream immediately, so the gc is executed very late.

    What I want to do is deleting the old cache when I command server to purge.
    MediaCache.clearAll() works like what I want except the number of the files.
    I want a API like
    I also tried gc() but it doesn't work.
    --> especially, Sanjose streaming, because the rejectSession() can't destroy the stream immediately.
    In addition, I reverse engineered MediaCache and tried to do clear() for a specific media file.
    I, however, can't remove the item of the HashMap.

    Do you have any suggestion ?
    If so, Please let me know.
    Take care.


    Why MediaCache API document does not have any description?
    Can I get the API docs with description?

    I think If I can find out how to disconnect the Sanjose streaming completely, gc() can work weill.
    If you know how to do, please let me know.
    Last edited by i5on9i; 01-14-2014 at 04:41 AM.

  2. #2


    As I understand, this is the only way to clear MediaCache items:
    How to purge an item from the cache (MediaCache)

    The item can not be flushed from the cache until there are no players referencing/playing the cached asset.


  3. #3
    Join Date
    Dec 2013


    Quote Originally Posted by salvadore View Post
    As I understand, this is the only way to clear MediaCache items:
    How to purge an item from the cache (MediaCache)

    The item can not be flushed from the cache until there are no players referencing/playing the cached asset.


    Updated right after some test.

    Hi, Salvadore.
    I have just tested with
    it causes the stream is destroyed immediately.
    I think it would help to purge immediately.(like what I said the below)

    However, If you have any suggestion, please let me know.
    Take care.

    Hi, Salvadore. Thanks for your answer.

    I know what you mean, and I also know that it is the way the MediaCache works.
    Therefore, I need solution for this.
    In my case, I will disconnect all the connections of the file which I am going to purge.

    I think there is 2 ways to resolve this.
    1. Disconnect and , right after, destroy stream Sanjo streaming(HDS)
    This could help the gc() work immediately after disconnection.
    Now, however, Until the HDS connection is destroyed, gc() does not work immediately, even I call the gc() method.
    When I tested with RTMS, I called gc() right after disconnect the current connections. At this time, gc() was executed right after I call it.

    2. If HDS connection can be destroyed immediately, I think only the way to purge immediately is expiring the cache file, which may cause re-loading.
    I've tried to remove the cacahe with MediaCache.clearAll() for test.
    At this time, all the cache files were deleted except the .media file which is being served.
    Though the .media file has remained, the new connection request for same file generated the new cache, which means the re-loading.
    Therefore, I need this kind of method, even I delete the .media file later by myself.

    Take care
    Last edited by i5on9i; 01-14-2014 at 06:51 PM.

  4. #4


    Hi Namhun,

    The mediaCache will only purge items during a gc run when there are no longer any references to that item. When you select an item to purge, it is marked so that it will be deleted on the first gc run after all references are closed.

    You should be able to speed up the process by doing the following.

    1. Obtain a write lock on the appInstance clientLock. This will prevent players from connecting while your script is running.
      WMSReadWriteLock clientLock = appInstance.getClientLockObj();
      	. . .

    2. Close all player connections to the stream you want to purge.

      Use client.setShutdownClient(true); for rtmp clients,

      appInstance.getVHost().getHTTPStreamerContext().getSessions().checkTimeout(System.currentTimeMillis( )); for http sessions and

      appInstance.getVHost().getRTPContext().shutdownRTPSession(rtpSession); for rtp sessions.

      You can get a list of players playing a stream name by using the following methods

      appInstance.getPlayStreamsByName(String name); for rtmp,
      appInstance.getHTTPStreamerSessions(String streamName); for HTTP and
      appInstance.getRTPSessions(String streamName); for rtp.

    3. Call mediaCache.flushStreamNameFromCache(streamName); for the item you want to purge.

    4. Call mediaCache.gc to run gc manually.

    5. Release the lock.

      	. . . 
      catch(Exception e)

    Make sure you use a try / catch / finally block to obtain and release the lock. This way, if your code does throw an exception, it will get caught and the lock will always be released.


Similar Threads

  1. Disable cache at MediaCache
    By solidx in forum General Forum
    Replies: 5
    Last Post: 05-02-2014, 05:02 AM
  2. MediaCache cache full - what's next?
    By romild0 in forum AddOn: Other AddOns
    Replies: 2
    Last Post: 09-27-2012, 08:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts