> For the complete documentation index, see [llms.txt](https://docs.jentis.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.jentis.com/developer-guide/variables/client-side-variables/public-function-scope/setlocalstorageitem.md).

# setLocalStorageItem

## `setLocalStorageItem` Function

#### Description

With this method, a value can be stored in the **localStorage** of the browser. A **TTL (Time-To-Live)** can be set to define how long the item should persist before being considered expired. If no TTL is set, the configured system default is used.

This function helps ensure client-side storage respects the JENTIS storage policy.

***

#### Parameters

| Name               | Type                    | Description                                                                                                                    |
| ------------------ | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `key`              | `String`                | The key under which the value is stored in localStorage                                                                        |
| `value`            | `Any`                   | The value to be stored (will be stringified internally)                                                                        |
| `ttl` *(optional)* | `Number` (milliseconds) | The duration the item should remain valid. If not set or too high, it will default to the configured `maximumStorageLifetime`. |

***

#### Returns

| Type      | Description                                                                                   |
| --------- | --------------------------------------------------------------------------------------------- |
| `Boolean` | Returns `true` if the item was successfully set, or `false` if localStorage is not available. |

***

#### Usage Example

```javascript
this.setLocalStorageItem("my_test_key", "my_value", 3600000);
```

Stores the value `"my_value"` under the key `"my_test_key"` for one hour (3600000 milliseconds).\
If the TTL exceeds the JENTIS configured `maximumStorageLifetime`, it will be automatically reduced to that maximum.

***

#### Important Notes

* The stored item will be saved in the following format:

  ```json
  {
    "value": "my_value",
    "ttl": 3600000,
    "expiry": 1652953200000
  }
  ```
* The method checks whether localStorage is available before attempting to write.
* If you define nested functions inside your codeblock, be aware that the `this` scope will not be available inside them.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.jentis.com/developer-guide/variables/client-side-variables/public-function-scope/setlocalstorageitem.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
