C# Class Bari.Core.Build.Cache.FileBuildCache

Build cache storing build outputs together with their actual dependency fingerprint in the file system.
Inheritance: IBuildCache
Mostrar archivo Open project: vigoo/bari

Public Methods

Method Description
Contains ( BuildKey builder, IDependencyFingerprint fingerprint ) : bool

Checks if the cache contains stored outputs for a given builder with a given dependency fingerprint

If IBuildCache.Restore will be also called, the cache must be locked first using the IBuildCache.LockForBuilder method.

ContainsAny ( BuildKey builder ) : bool

Checks if the cache contains stored outputs for a given builder with any dependency fingerprint

Dispose ( ) : void
FileBuildCache ( [ cacheRoot, IProtocolSerializer protocolSerializer ) : System

Constructs the cache

LockForBuilder ( BuildKey builder ) : void

Locks the cache for a given builder.

Until calling IBuildCache.UnlockForBuilder, it is guaranteed that no IBuildCache.Store operation will be ran for the given builder from other threads.

Restore ( BuildKey builder, IFileSystemDirectory targetRoot, bool aggressive, Regex aggressiveExceptions = null ) : ISet

Restores the stored files for a given builder to a file system directory

The cache only stores the latest stored results and this is what will be restored to the target directory. To verify if it was generated with the correct dependency fingerprint, use IBuildCache.Contains.

To ensure thread safety, use IBuildCache.LockForBuilder.

Store ( BuildKey builder, IDependencyFingerprint fingerprint, IEnumerable outputs, IFileSystemDirectory targetRoot ) : void

Store build outputs in the cache by reading them from the file system

UnlockForBuilder ( BuildKey builder ) : void

Removes the lock put by the IBuildCache.LockForBuilder method.

Private Methods

Method Description
BeAggressive ( IEnumerable aggressiveExceptions, string fullPath ) : bool
ComputeChecksum ( HashAlgorithm hash, IFileSystemDirectory root, string path ) : byte[]
CopyIfDifferent ( IFileSystemDirectory sourceDirectory, string sourceFileName, IFileSystemDirectory targetRoot, string targetRelativePath ) : void

Copies a source file to a target location, but only if it does not exist yet, with the same MD5 checksum as the source

GetCacheDirectoryName ( BuildKey builder ) : string

Gets the directory name associated with a given Builder key

GetOrCreateLock ( BuildKey builder ) : ReaderWriterLockSlim

Gets an existing lock or creates a new one

SaveDependencyFingerprint ( IDependencyFingerprint fingerprint, IFileSystemDirectory cacheDir ) : void

Saves a dependency fingerprint to the cache directory

SaveOutputs ( IEnumerable outputs, IFileSystemDirectory targetRoot, IFileSystemDirectory cacheDir ) : void

Copies output files to the cache directory, and also saves a '.names' file referring to he original target relative paths of these files.

Method Details

Contains() public method

Checks if the cache contains stored outputs for a given builder with a given dependency fingerprint

If IBuildCache.Restore will be also called, the cache must be locked first using the IBuildCache.LockForBuilder method.

public Contains ( BuildKey builder, IDependencyFingerprint fingerprint ) : bool
builder BuildKey Builder key
fingerprint IDependencyFingerprint Current dependency fingerprint
return bool

ContainsAny() public method

Checks if the cache contains stored outputs for a given builder with any dependency fingerprint
public ContainsAny ( BuildKey builder ) : bool
builder BuildKey Builder key
return bool

Dispose() public method

public Dispose ( ) : void
return void

FileBuildCache() public method

Constructs the cache
public FileBuildCache ( [ cacheRoot, IProtocolSerializer protocolSerializer ) : System
cacheRoot [ Root directory where the cache will store its contents.
protocolSerializer IProtocolSerializer The serializer to be used for saving dependency fingerprint protocols
return System

LockForBuilder() public method

Locks the cache for a given builder.

Until calling IBuildCache.UnlockForBuilder, it is guaranteed that no IBuildCache.Store operation will be ran for the given builder from other threads.

public LockForBuilder ( BuildKey builder ) : void
builder BuildKey Builder key
return void

Restore() public method

Restores the stored files for a given builder to a file system directory

The cache only stores the latest stored results and this is what will be restored to the target directory. To verify if it was generated with the correct dependency fingerprint, use IBuildCache.Contains.

To ensure thread safety, use IBuildCache.LockForBuilder.

public Restore ( BuildKey builder, IFileSystemDirectory targetRoot, bool aggressive, Regex aggressiveExceptions = null ) : ISet
builder BuildKey Builder key
targetRoot IFileSystemDirectory Target file system directory
aggressive bool If true, files in the target directory won't be checked by hash before overriding them
aggressiveExceptions Regex Exceptions to the aggresivve mode. Can be null if not used.
return ISet

Store() public method

Store build outputs in the cache by reading them from the file system
public Store ( BuildKey builder, IDependencyFingerprint fingerprint, IEnumerable outputs, IFileSystemDirectory targetRoot ) : void
builder BuildKey Builder key (first part of the key)
fingerprint IDependencyFingerprint Dependency fingerprint created when the builder was executed (second part of the key)
outputs IEnumerable Target-relative path of the build outputs to be cached
targetRoot IFileSystemDirectory File system abstraction of the root target directory
return void

UnlockForBuilder() public method

Removes the lock put by the IBuildCache.LockForBuilder method.
public UnlockForBuilder ( BuildKey builder ) : void
builder BuildKey Builder key
return void