Table of Contents

Class InMemoryCompilerCache

Namespace
Ecng.Compilation
Assembly
Ecng.Compilation.dll

An in-memory implementation of ICompilerCache that stores compiled assemblies in memory.

public class InMemoryCompilerCache : ICompilerCache
Inheritance
InMemoryCompilerCache
Implements
Derived
Inherited Members
Extension Methods

Constructors

InMemoryCompilerCache(TimeSpan)

Initializes a new instance of the InMemoryCompilerCache class with a specified timeout.

public InMemoryCompilerCache(TimeSpan timeout)

Parameters

timeout TimeSpan

Cache timeout.

Properties

Count

Gets the number of cached assemblies.

public virtual int Count { get; }

Property Value

int

Timeout

Gets the cache timeout.

public TimeSpan Timeout { get; }

Property Value

TimeSpan

Methods

Add(string, IEnumerable<string>, IEnumerable<string>, byte[])

Adds a compiled assembly to the cache.

public virtual void Add(string ext, IEnumerable<string> sources, IEnumerable<string> refs, byte[] assembly)

Parameters

ext string

The file extension used in key generation.

sources IEnumerable<string>

The source code files.

refs IEnumerable<string>

The referenced assemblies.

assembly byte[]

The compiled assembly bytes to cache.

Clear()

Clears all cached assemblies.

public virtual void Clear()

GetKey(string, IEnumerable<string>, IEnumerable<string>)

Generates a cache key based on the file extension, source code files, and referenced assemblies.

protected static string GetKey(string ext, IEnumerable<string> sources, IEnumerable<string> refs)

Parameters

ext string

The file extension used in key generation.

sources IEnumerable<string>

The source code files.

refs IEnumerable<string>

The referenced assemblies.

Returns

string

The key.

GetTill()

Gets the expiration time for a cache entry.

protected DateTime GetTill()

Returns

DateTime

The expiration time for a cache entry.

Init()

Initializes the cache.

public virtual void Init()

Remove(string)

Removes a cached assembly based on the key.

protected bool Remove(string key)

Parameters

key string

The key.

Returns

bool

Operation result.

Remove(string, IEnumerable<string>, IEnumerable<string>)

Removes a cached assembly based on extension, sources, and references.

public virtual bool Remove(string ext, IEnumerable<string> sources, IEnumerable<string> refs)

Parameters

ext string

The file extension used in key generation.

sources IEnumerable<string>

The source code files.

refs IEnumerable<string>

The referenced assemblies.

Returns

bool

true if the assembly was removed; otherwise, false.

Set(string, byte[])

Adds a compiled assembly to the in-memory cache.

protected void Set(string key, byte[] assembly)

Parameters

key string

The key.

assembly byte[]

Compiled assembly.

TryGet(string, out byte[])

Tries to retrieve a cached assembly based on the key.

protected bool TryGet(string key, out byte[] assembly)

Parameters

key string

The key.

assembly byte[]

Compiled assembly.

Returns

bool

Operation result.

TryGet(string, IEnumerable<string>, IEnumerable<string>, out byte[])

Tries to retrieve a cached assembly based on extension, sources, and references.

public virtual bool TryGet(string ext, IEnumerable<string> sources, IEnumerable<string> refs, out byte[] assembly)

Parameters

ext string

The file extension used in key generation.

sources IEnumerable<string>

The source code files.

refs IEnumerable<string>

The referenced assemblies.

assembly byte[]

When this method returns, contains the cached assembly if found; otherwise, null.

Returns

bool

true if the assembly was retrieved from the cache; otherwise, false.