# Saving Custom Data

When customizing the CMS there will come a point where you want to save some data that is not content or media and re-use it.

For this you can use GlobalData, which stores a string with an alias.&#x20;

```csharp
public class GlobalData
{
    public Guid Id { get; set; } = Guid.NewGuid().NewSequentialGuid();
    public string? Alias { get; set; }
    public string? Data { get; set; }
    public DateTime DateCreated { get; set; } = DateTime.UtcNow;
    public DateTime DateUpdated { get; set; } = DateTime.UtcNow;
}
```

You can save data into Global Data using the following method, you need to serialise your data into a string

```csharp
var saveResult = await Mediator.Send(new SaveGlobalDataCommand
{
    GlobalData = new GlobalData
    {
        Alias = "YourAlias",
        Data = "SerialisedData"
    }
});
```

Once it's saved it's very easy to get the data out by using this extension method

```csharp
var mydata= await Mediator.GetGlobalData<MyDataType>("YourAlias");
```

Global data is cached by default and auto flushed whenever `SaveGlobalDataCommand` is used. However, if you want to bypass the cache and manually call for the data you can use

```csharp
var globalData = await mediator.Send(new GetGlobalDataCommand
{
    Alias = "YourAlias", 
    Cached = false
});
```

{% hint style="info" %}
Did you know, we use Global Data to power the Global Settings in the CMS
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://aptitude.gitbook.io/zaubercms/extending-zaubercms/saving-custom-data.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
