andrewdavey/cassette — Issue #142: BundleCache is not used if missing image referenced in stylesheet
Author: nazjunaid
Created: 2012-01-23 14:31:01+00:00
State: open

Related to issue 55 and issue 57

We have noticed a large amount of filelocking errors on our production servers during application recycle or config changing which appear to be happening during cassette initialization.

```
Server stack trace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, IsolatedStorageFile isf)
at System.IO.IsolatedStorage.IsolatedStorageFile.OpenFile(String path, FileMode mode, FileAccess access, FileShare share)
at Cassette.IO.IsolatedStorageFileWrapper.Open(FileMode mode, FileAccess access, FileShare fileShare) in C:\Websites\Git\cassette\src\Cassette\IO\IsolatedStorageFileSystem.cs:line 32
at Cassette.Persistence.ModuleCache`1.SaveModule(T module) in C:\Websites\Git\cassette\src\Cassette\Persistence\ModuleCache.cs:line 247
at Cassette.Persistence.ModuleCache`1.SaveModuleContainer(IModuleContainer`1 moduleContainer) in C:\Websites\Git\cassette\src\Cassette\Persistence\ModuleCache.cs:line 164
at Cassette.ModuleConfiguration.GetOrCreateCachedModuleContainer[T](T[] modules) in C:\Websites\Git\cassette\src\Cassette\ModuleConfiguration.cs:line 104
at Cassette.ModuleConfiguration.CreateModuleContainer[T](Boolean useCache) in C:\Websites\Git\cassette\src\Cassette\ModuleConfiguration.cs:line 85
at Cassette.ModuleConfiguration.<>c__DisplayClass3.b__1(KeyValuePair`2 kvp) in C:\Websites\Git\cassette\src\Cassette\ModuleConfiguration.cs:line 75
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElem
```

After debugging the issue locally I think it could be because of a bug where the BundleCache isn't being used in our application due to missing images referenced in styleheets which trip up this check in the FilesAreUpToDate.

```
if (files.Any(f => !f.Exists)) return false;
```

The files array seems to include references to missing images so this check always returns false and cassette goes through the costly initialization every time.

As a work around I modified the ExpandCssUrlsAssetTransformer and removed the following check.

```
if (!file.Exists) return;
```

This now means cassette throws exception but only in debug=false configuration if a reference to an image is not there which isn't ideal.

Ideally I think the caching mechanism would just ignore the broken references.