                 index = _.sortedIndex _archivedTasks, task, (task) -> -(new Date(task.completionDate).getTime())
                 _archivedTasks.splice index, 0, task
 
+                # invalid cache
+                _invalidCache task
+
                 @emit 'change'
 
         handle ActionTypes.RESTORE_TASK, (cid) ->

        return tasksList.filter (task) -> task.tags.length is 0

    getByTags: (tags) ->

        {tasksList} = _getTaskLists()

        # returns all unselected tags if the tag filter is empty

                    .filter (tag) -> tag.isExcluded
                    .map mapValue

                # the cache key is a unique hash based on tag selection
                cacheKey = [].concat tags # clone the tags

                    # sort the tag list so the cache is stable. I.e. cache is
                    # the same for tag1/tag2 and tag2/tag1
                    .sort (a, b) ->
                        if a.label > b.label
                            return 1
                        else if a.label > b.label
                            return -1
                        else
                            return 0

                    # lists are different if they have the same tags but some
                    # of them are included and others are excluded
                    .map (tag) ->
                        prefix = if tag.isExcluded then '!' else ''
                        return "#{prefix}#{tag.label}"

                    # '#' is the safest separator because it's used to mark the
                    # beginning of a tag
                    .join '#'

                cachedList = _cache[cacheKey]
                if cachedList?
                    filteredTasksList = cachedList
                else
                    # When there are no included tags, it means all tasks should
                    # be selected.
                    filteredTasksList = filteredTasksList.filter (task) ->
                        return (TaskUtils.containsTags(task, includedTags) or \
                               noInclusion) and \
                               TaskUtils.doesntContainsTags(task, excludedTags)

                    # add in cache
                    _cache[cacheKey] = filteredTasksList

            if _searchQuery?
                regex = new RegExp _searchQuery, 'i'
