Copied to clipboard

Flag this post as spam?

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


  • progproger 52 posts 130 karma points
    Feb 25, 2016 @ 10:40
    progproger
    0

    GetContentByTag method cache problem

    Hi,

    I tried to add tag to document programmatically:

     var cs = ApplicationContext.Current.Services.ContentService;
    
        var item = cs.GetById(1227);
        item.SetValue("itemTags", "testTagName");
    
        cs.SaveAndPublishWithStatus(item);
        cs.RePublishAll();    
        umbraco.library.RefreshContent();
    

    In another page i need to filter items by tag like this:

    var filteredItemsByTag = Umbraco.TagQuery.GetContentByTag("testTagName");
    

    But this method still does not return an item which was added above. It works only if i "Save and Publish" current item from admin backoffice.

    I see in Umbraco.Core that "GetContentByTag " method gets value from RuntimeCacheProvider, which has "Clear()" method, but class is internal, so i can't use it.

    Is there any way to get an item?

    Thanks

  • Erik Rosenlew 7 posts 38 karma points
    Feb 25, 2016 @ 19:20
    Erik Rosenlew
    0

    Hi

    I have the same problem. Works fine from backoffice but not when tags are added via API.

    Hope for answer.

  • Erik Rosenlew 7 posts 38 karma points
    Feb 26, 2016 @ 09:11
    Erik Rosenlew
    1

    Hi!

    Using IContent SetTags fixed my problem. This has been discussed in this post also: https://our.umbraco.org/forum/developers/api-questions/74836-setting-tags-on-images-via-icontentbase

    Hope it helps!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies