# Cache

The moss sdk provides a simple persistent cache that it will be internally used for example the scheduler.

When using the cache a `.cache` folder will be created. Every item of the cache will be represented by it's own file named by its key. The default cache serializes all items as the [cbor](https://de.wikipedia.org/wiki/Concise_Binary_Object_Representation) binary format. A class is cachable if it has an IShapable implementation. You can use the source generator of [PolyType](https://github.com/eiriktsarpalis/PolyType) by annoating your class with `[GenerateShape]`

## Working with the cache

The cache is accessible with `MossExtension.Instance.Cache` and has the following methods:

<pre class="language-csharp"><code class="lang-csharp">bool HasKey(string key)
void Set&#x3C;T>(string key, T value) // the value has to be an <a data-footnote-ref href="#user-content-fn-1">IShapable&#x3C;T></a>
T? Get&#x3C;T>(string key)
void Remove(string key)
</code></pre>

You can also implement your own cache by implementing the `ICache` interface.

[^1]: ```
    https://github.com/eiriktsarpalis/PolyType
    ```
