Giter Site home page Giter Site logo

Comments (3)

jodydonetti avatar jodydonetti commented on May 18, 2024 1

Pinging @JoeShook because of course 😄

from fusioncache.

jodydonetti avatar jodydonetti commented on May 18, 2024 1

The plugins subsystem has been released with v0.1.5 🎉

from fusioncache.

jodydonetti avatar jodydonetti commented on May 18, 2024

I just published a new branch with the plugins subsystem here.

How to create a plugin

Write a class that implements the IFusionCachePlugin interface, basically just the Start and Stop methods, like this.

Of course it can also accept its own set of options, typically modelled via IOptions<MyPluginType> and friends.

How to use a plugin via DI

Register your plugin type in the DI container (better before registering FusionCache itself) to respond to the IFusionCachePlugin service as a singleton, like here: when a FusionCache instance will be requested, all plugin types registered will be auto-discovered, added (and started) automatically.

Of course you can also define your own custom ext method (like this one) to be a better .NET citizen.

Example:

[...]
services.AddSingleton<IFusionCachePlugin, MyPlugin>();
services.AddFusionCache();
[...]

or with a custom ext method + custom options:

[...]
services.AddMyFusionCachePlugin(options => {
  options.Whatever = 42;
});
services.AddFusionCache();
[...]

How to use a plugin without DI

Just create an instance of your plugin and pass it to the cache.AddPlugin method, like here.

Remember that, in case the Start method of your plugin throws and exception, an InvalidOperationException would also be thrown by the AddPlugin method itself (with the original exception as the inner one).

Removing a plugin

If you need continue using a FusionCache instance but want to remove a plugin you've previously added, you can call the cache.RemovePlugin method: it will automatically call the Stop method of the plugin and then remove it.

If instead you just want to clean things up "at the end" (and you should do it), you don't have to do anything because when the FusionCache instance will be disposed, all added plugins will be stopped and removed automatically.

Opinions?

Anything would be appreciated, thanks!

from fusioncache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.