Finally found what was the root cause. There is an issue with BinaryFileManager.IsCached method. It does not account if file was unpublished.
When you call IsCached method it will get lastPublishedDate, however lastPublishedDate for unpublished binary file is DateTime.MinValue. Based on my testing IsCached method does not handle situation when lastPublishedData is DateTime.MinValue.
To fix it I added next code:
if (lastPublishedDate == DateTime.MinValue)
{
//Last published data is minValue, so file has been unpublished.
Log.Debug(
"Binary at path '{0}' has been unpublished",
localFilePath);
return false;
}
One more issue that I noticed in that method is that localization.LastRefresh
and lastPublishedDate
are using different time zones.
Also added next line to fix time zone difference:
lastPublishedDate = lastPublishedDate.ToLocalTime();
Hopefully it will be fixed in the next DXA release