How to invalidate SPList cache


  • How to invalidate SPList cache so that the LastItemModifiedDate is current?

    The following code is executed periodically to check if the SPList.LastItemModifiedDate has changed. The _site and _web members are set the first time and not updated.

    The problem is after a list item is edited using the browser, the modified date is stale. If OpenWeb is called each time, the modified date is current, but I'd rather not call OpenWeb each time.

    I thought that "list = _web.Lists[Title];" would query for a new list with the current modified date, but that doesn't seem to update the list.

    I tried "SPSite.InvalidateCacheEntry(new Uri(_site.Url), _site.ID)", but after that _web.Lists[Title] doesn't return an updated list. I looked at SPListCollection.EnsureListsData and SPList.EnsurePropsFresh, but these are protected methods.


    // Initialize web site if it isn't initialized.

    if (_siteUrl == null)

    if (_site == null)
        _site =
    new SPSite(_siteUrl);

    if (_web == null)
        _web = _site.OpenWeb();

    SPList list = null;
        list = _web.Lists[Title];
    catch (Exception e)
        throw new ApplicationException("Target list does not exist.", e);

    // If the target collection does not exist
    // or the web target list has been modified,
    // create a new target collection.
    DateTime date = list.LastItemModifiedDate;
    if ((_targets == null) || (date != _lastItemModifiedDate))

    Wednesday, October 01, 2008 12:22 PM


  • There maybe some alternatives. If you are keeping the SPWeb object alive you can try using the GetList, GetListFromUrl, or GetListsOfType methods to retrieve a fresh updated list.
    Monday, October 06, 2008 7:27 PM