> 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/codeblocks/public-function-scope/setlocalstorageitem.md).

# setLocalStorageItem

## `this.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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
