Skip to content

upm-packages/CAFU.KeyValueStore

Repository files navigation

CAFU KeyValueStore

Installation

Use Command Line

upm add package dev.upm-packages.cafu.keyvaluestore

Note: upm command is provided by this repository.

Edit Packages/manifest.json

{
  "dependencies": {
    // (snip)
    "dev.upm-packages.cafu.keyvaluestore": "[latest version]",
    // (snip)
  },
  "scopedRegistries": [
    {
      "name": "Unofficial Unity Package Manager Registry",
      "url": "https://upm-packages.dev",
      "scopes": [
        "com.stevevermeulen",
        "jp.cysharp",
        "dev.upm-packages"
      ]
    }
  ]
}

Usages

Zenject Installer

KeyValueStoreInstaller.Install(Container, DataStoreType.PlayerPrefs);

DataStore Types

Type Description
PlayerPrefs Using UnityEngine.PlayerPrefs
Memory Using IDictionary<>

Handle values

using CAFU.KeyValueStore.Application.Interface;
using System.Threading.Tasks;

public class Foo
{
    [Inject] private IKeyValueStore KeyValueStore { get; }

    public async Task Bar()
    {
        var value = "";

        if (await KeyValueStore.Has("key"))
        {
            value = await KeyValueStore.Get<string>("key", "default value");
        }

        await KeyValueStore.Set<string>("key", "value is " + value);
    }
}

It is strongly recommended that you use UniTask instead of Task if you can.

About

Provides a simple Key-Value store

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages