Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Chad 18 posts 122 karma points
    May 06, 2019 @ 13:34
    Chad
    0

    Media Cache vs Media Service

    I have a test service that is getting random media from umbraco. I was originally using the media cache from the umbraco context but I noticed that all of my media stopped being accessible this way.

    Media Cache:

                var imageMedia = _umbracoContext.MediaCache.GetByContentType(Image.GetModelContentType()).ToList();
    

    Media Service:

                var imageMediaCount = _mediaService.Count(Image.ModelTypeAlias);
            var imageMedia = _mediaService.GetPagedOfType(Image.GetModelContentType().Id, 0, imageMediaCount, out var totalRecords).ToList();
    

    Which one should I be using? If it's the cache, why is my media gone? I'd like to get all of my image media into a single list. I've also ran into an issue with the media service and can't find a way to access the url of the image.

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    May 06, 2019 @ 14:36
    Søren Gregersen
    0

    if you are using this code for the frontend, you need to used the cache-version, otherwise your site may use all the CPU on the database server, causing the db to become unresponsive

  • Chad 18 posts 122 karma points
    May 06, 2019 @ 14:47
    Chad
    0

    How does media get into the media cache? I have about 30 images in my media section and when I try to find them with the media cache there are 0 results. A few days ago it was finding all 30 of my images and now it is finding none. The media service is able to find everything though. But I'd rather deal with IPublishedContent than IMedia.

Please Sign in or register to post replies

Write your reply to:

Draft