Skip to content

[DISCUSSION] Feature idea for plugin development: standardize paths for cache and persistent data #3136

@Yusyuriv

Description

@Yusyuriv

The problem

Right now every plugin does its own thing when it needs to cache data or to save persistent data.

My proposal

Standardize paths for cache and persistent data and provide APIs both for C#/F# and for JS/Python plugins. The difference between persistent data directory and cache directory is that the cache directory should always be safe to delete. The plugin might need to regenerate the data on startup or on query, but it should still work. I had to do delete cache data myself a few times for the built-in Program plugin. Persistent data, as the name suggests, should not be deleted manually.

Cache

  • The path to the cache directory would be FlowLauncher/Cache/{PLUGIN_ID}
  • IPublicApi gets several additional methods, most of which are not necessary, but are there for convenience. Method names are just rough ideas and are subject to change:
    • string GetCacheRootDirectoryPath() — returns the absolute path to the cache directory. Creates it if it does not exist yet.
    • void SaveCacheJsonFile<T>(string path, T data) — serializes data to JSON and saves it in a file. SaveCacheJsonFile("my-data.json", myData)
    • T? ReadCacheJsonFile<T>(string path) — reads the JSON file from a file in the current plugin's cache directory and deserializes it, returning the deserialized object. ReadCacheJsonFile<MyData>("my-data.json")
    • void SaveCacheTextFile(string path, string data) — same as the JSON one, but without serialization, for saving simple strings. SaveCacheTextFile("my-data.txt", myString)
    • string ReadCacheTextFile(string path) — same as the JSON one, but without deserialization, for reading simple strings. ReadCacheTextFile("my-data.txt")
    • string GetCacheFilePath(string path) — returns the absolute path to the file in the current plugin's cache directory, creating directories recursively if they don't exist. This if for when the data the plugin needs to save is not a simple text or JSON file. For example, if the plugin needs to cache images or if it needs to create an SQLite database
    • void ClearCache() — remove all files from the current plugin's cache directory

Persistent data

  • The path to the persistent data directory would be FlowLauncher/Settings/{PLUGIN_NAME}-{PLUGIN_ID}/PersistentData (the current settings directory + /PersistentData) or FlowLauncher/PersistentData/{PLUGIN_ID}, whichever one looks better. I mentioned the Settings directory first because some users might be backing up their settings already, so they would also begin backing up plugins' persistent data this way without the need to manually add another directory to their backup software.
  • IPublicApi gets additional methods, similar to the cache ones:
    • string GetPersistentDataRootDirectory()
    • void SavePersistentJsonFile<T>(string pathToJsonFile, T data)
    • T? ReadPersistentJsonFile<T>()
    • void SavePersistentTextFile(string path, string data)
    • void ReadPersistentTextFile(string path)
    • string GetPersistentFilePath(string path)
    • void ClearPersistentData()

Conclusion

I think this would simplify developing plugins that need to cache or save data. I'd like to hear your opinions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions