magic.lambda.caching
17.2.0
dotnet add package magic.lambda.caching --version 17.2.0
NuGet\Install-Package magic.lambda.caching -Version 17.2.0
<PackageReference Include="magic.lambda.caching" Version="17.2.0" />
paket add magic.lambda.caching --version 17.2.0
#r "nuget: magic.lambda.caching, 17.2.0"
// Install magic.lambda.caching as a Cake Addin #addin nuget:?package=magic.lambda.caching&version=17.2.0 // Install magic.lambda.caching as a Cake Tool #tool nuget:?package=magic.lambda.caching&version=17.2.0
magic.lambda.caching - Caching from Hyperlambda
This project contains caching helper slots for Hyperlambda. More specifically this project provides the following slots.
- [cache.set] - Adds the specified item to the cache
- [cache.get] - Returns a previously cached item, if existing, if not returns nothing
- [cache.try-get] - Attempts to retrieve an item from cache, and if not existing, invokes [.lambda] to create item, saves the resulting item to the cache, before returning the item to caller
- [cache.clear] - Completely empties cache, optionally taking a filter condition
- [cache.list] - Lists all items in cache, optionally taking a filter condition
- [cache.count] - Returns the number of cache items in total, optionally taking a filter condition
All of the above slots requires a key as its value, and/or a filter argument, as the value of the identity node for the invocation of the slot. Notice, the cache can only persist string values, implying if you want to store something else besides a string, you'll need to correctly convert the object before storing it into your cache, and correctly convert it after extracting it again later. If you need to preserve typing information, you can store Hyperlambda strings into your cache.
How to use [cache.set]
Invoke this slot to save an item to the cache. The slot takes 3 properties, which are as follows.
- Value of node, being the key for your cache item.
- [value] - The item to actually save to the cache. If you pass in null, any existing cache items matching your key will be removed
- [expiration] - Number of seconds to keep the item in the cache. Defaults to 5
Below is an example of a piece of Hyperlambda that simply saves the value of "Howdy world" to your cache, using "cache-item-key" as the key for the cache item.
cache.set:cache-item-key
expiration:5
value:Howdy world
To remove the above item, you can use the following Hyperlambda.
cache.set:cache-item-key
How to use [cache.get]
Returns an item from your cache, or null if there are no items matching the specified key. Below is an example of retrieving the item we saved to the cache above.
cache.get:cache-item-key
How to use [cache.try-get]
This slot checks your cache to look for an item matching your specified key, and if not found, it will invoke its [.lambda] argument, and save its returned value to the cache with the specified key, before returning the created item to caller.
cache.try-get:cache-key
expiration:5
.lambda
return:Howdy world
If you are using the default memory based cache, then this slot is implemented in such a way that only the first invocation towards the specified key will actually execute your [.lambda] object, allowing you to have very expensive executions to create your items, that you want to store into the cache, without experiencing race conditions, or having more than one thread actually create the item and store into the cache. Notice, this is not true if you are using an out of process cache implementation, such as the one found in the "magic.data.cql" project. This should in general be your "goto slot" whenever you want to use the cache slots in this project.
How to use [cache.clear]
This is a shorthand slot to completely clear cache, removing all items.
cache.set:cache-item-key
expiration:5
value:Howdy world
cache.clear
cache.get:cache-item-key
Notice, the above Hyperlambda should not return any item in its last invocation to [cache.get] since the cache was cleared before invoking it. The slot also optionally takes a filter argument as its value, which if provided, will only delete items starting out with the specified filter. Usage example can be found below.
cache.clear:foo.bar
The above will only remove cache items having a key that starts out with "foo.bar" implying that for instance the following items will be cleared.
- foo.bar
- foo.bar.xyz1
- foo.bar.xyz2
While an item with a key of "x.foo.bar" will not be removed. This allows you to "namespace" your cache items, and clearing out for instance all cache items matching the specified namespace in one invocation.
How to use [cache.list]
Lists all items in cache, and returns to caller.
cache.set:cache-item-key
expiration:5
value:Howdy world
cache.list
This slot also supports the following optional arguments.
- [limit] - Maximum number of items to return.
- [offset] - Offset of where to start returning items.
- Filter as value of node being the filter condition declaring which items to return. See the [cache.clear] slot to understand how it works, since this argument works in the exact same way, assuming your filter is a "namespace".
How to use [cache.count]
This slot works similarly to the [cache.list] slot, except it only returns the number of items. Below is an example of creating a new cache entry, for then to count how many cache items exists in your cache.
cache.set:cache-item-key
expiration:5
value:Howdy world
cache.count
Hyperlambda caching internals
Internally the cache implementation is not using the MemoryCache
from .Net, since this class
suffers from a whole range of problems in regards to its API, such as not being able to count or
iterate items, etc. Hence, the actual implementation is completely custom, and is based upon
the IMagicCache
interface, which by default is wired up towards its MagicMemoryCache
implementation. This is a conscious choice, since first of all the IMemoryCache
that .Net
provides out of the box is really slow, in addition to that it is missing a lot of crucial
parts expected from a mature memory based cache implementation.
If you want to access the actual cache from C# or something, make sure you use it through the dependency
injected IMagicCache
interface, providing you with the implementation class needed to consume
it from C#. This interface has a lot of nifty methods you can use to have a robust and fast memory
based cache implementation in your C# code. However, it is a memory based cache. If you need better
caching features going beyond what a basic memory based cache implementation can achieve, you might
want to use the out of process based cache that can be found in the project called "magic.data.cql".
The latter allows for storing cache items in Cassandra or ScyllaDB.
If you consume the IMagicCache
interface from your own C# code, you can create "hidden"
cache items that are only possible to retrieve from C# code and not from Hyperlambda. This allows
you to create a C# only type of cache, where items added as hidden cannot in any ways what so ever
be retrieved from Hyperlambda. This is useful for C# only type of cache items that you don't want to
expose to Hyperlambda code. The "magic.lambda.slots" project for instance is internally storing its
dynamically created slots in the cache as "hidden" items.
Project website
The source code for this repository can be found at github.com/polterguy/magic.lambda.caching, and you can provide feedback, provide bug reports, etc at the same place.
Copyright and maintenance
The projects is copyright Thomas Hansen 2023 - 2024, and professionally maintained by AINIRO.IO.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- magic.node.extensions (>= 17.2.0)
- magic.signals.contracts (>= 17.2.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on magic.lambda.caching:
Package | Downloads |
---|---|
magic.library
Helper project for Magic to wire up everything easily by simply adding one package, and invoking two simple methods. When using Magic, this is (probably) the only package you should actually add, since this package pulls in everything else you'll need automatically, and wires up everything sanely by default. To use package go to https://polterguy.github.io |
|
magic.lambda.slots
Helper slots for Magic, to allow you to dynamically create dynamic slots in your own Hyperlambda. To use package go to https://polterguy.github.io |
|
magic.data.cql
CQL data adapters for Magic to store files and folders, etc. To use package go to https://polterguy.github.io |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
17.2.0 | 526 | 1/22/2024 |
17.1.7 | 246 | 1/12/2024 |
17.1.6 | 217 | 1/11/2024 |
17.1.5 | 230 | 1/5/2024 |
17.0.1 | 278 | 1/1/2024 |
17.0.0 | 419 | 12/14/2023 |
16.11.5 | 434 | 11/12/2023 |
16.9.0 | 440 | 10/9/2023 |
16.7.0 | 658 | 7/11/2023 |
16.4.1 | 502 | 7/2/2023 |
16.4.0 | 483 | 6/22/2023 |
16.3.1 | 461 | 6/7/2023 |
16.3.0 | 431 | 5/28/2023 |
16.1.9 | 766 | 4/30/2023 |
15.10.11 | 618 | 4/13/2023 |
15.9.1 | 746 | 3/26/2023 |
15.9.0 | 617 | 3/24/2023 |
15.8.2 | 711 | 3/20/2023 |
15.7.0 | 596 | 3/6/2023 |
15.5.0 | 2,001 | 1/28/2023 |
15.2.0 | 1,062 | 1/18/2023 |
15.1.0 | 1,548 | 12/28/2022 |
14.5.7 | 1,122 | 12/13/2022 |
14.5.5 | 1,233 | 12/6/2022 |
14.5.1 | 1,121 | 11/23/2022 |
14.5.0 | 1,108 | 11/18/2022 |
14.4.5 | 1,268 | 10/22/2022 |
14.4.1 | 1,295 | 10/22/2022 |
14.4.0 | 1,197 | 10/17/2022 |
14.3.1 | 1,862 | 9/12/2022 |
14.3.0 | 1,224 | 9/10/2022 |
14.1.3 | 1,535 | 8/7/2022 |
14.1.2 | 1,242 | 8/7/2022 |
14.1.1 | 1,262 | 8/7/2022 |
14.0.14 | 1,321 | 7/26/2022 |
14.0.12 | 1,290 | 7/24/2022 |
14.0.11 | 1,204 | 7/23/2022 |
14.0.10 | 1,204 | 7/23/2022 |
14.0.9 | 1,233 | 7/23/2022 |
14.0.8 | 1,356 | 7/17/2022 |
14.0.5 | 1,394 | 7/11/2022 |
14.0.4 | 1,430 | 7/6/2022 |
14.0.3 | 1,315 | 7/2/2022 |
14.0.2 | 1,246 | 7/2/2022 |
14.0.0 | 1,739 | 6/25/2022 |
13.4.0 | 2,633 | 5/31/2022 |
13.3.4 | 2,024 | 5/9/2022 |
13.3.0 | 1,790 | 5/1/2022 |
13.2.0 | 1,832 | 4/21/2022 |
13.1.0 | 1,680 | 4/7/2022 |
13.0.0 | 1,333 | 4/5/2022 |
11.0.5 | 2,346 | 3/2/2022 |
11.0.4 | 1,361 | 2/22/2022 |
11.0.3 | 1,394 | 2/9/2022 |
11.0.2 | 1,417 | 2/6/2022 |
11.0.1 | 542 | 2/5/2022 |
11.0.0 | 1,436 | 2/5/2022 |
10.0.21 | 1,406 | 1/28/2022 |
10.0.20 | 1,074 | 1/27/2022 |
10.0.19 | 1,099 | 1/23/2022 |
10.0.18 | 1,050 | 1/17/2022 |
10.0.15 | 1,186 | 12/31/2021 |
10.0.14 | 813 | 12/28/2021 |
10.0.8 | 1,442 | 12/22/2021 |
10.0.7 | 766 | 12/22/2021 |
10.0.5 | 746 | 12/18/2021 |
9.9.9 | 1,702 | 11/29/2021 |
9.9.3 | 912 | 11/9/2021 |
9.9.2 | 620 | 11/4/2021 |
9.9.0 | 750 | 10/30/2021 |
9.8.9 | 718 | 10/29/2021 |
9.8.7 | 689 | 10/27/2021 |
9.8.6 | 644 | 10/27/2021 |
9.8.5 | 719 | 10/26/2021 |
9.8.0 | 1,387 | 10/20/2021 |
9.7.9 | 670 | 10/19/2021 |
9.7.5 | 1,486 | 10/14/2021 |
9.7.0 | 868 | 10/9/2021 |
9.6.6 | 1,241 | 8/14/2021 |
9.2.0 | 6,236 | 5/26/2021 |
9.1.4 | 1,279 | 4/21/2021 |
9.1.0 | 1,075 | 4/14/2021 |
9.0.0 | 840 | 4/5/2021 |
8.9.9 | 1,010 | 3/30/2021 |
8.9.3 | 1,544 | 3/19/2021 |
8.9.2 | 1,043 | 1/29/2021 |
8.9.1 | 1,024 | 1/24/2021 |
8.9.0 | 1,121 | 1/22/2021 |
8.6.9 | 2,929 | 11/8/2020 |
8.6.6 | 1,947 | 11/2/2020 |
8.6.2 | 2,570 | 10/30/2020 |
8.6.0 | 2,016 | 10/28/2020 |
8.5.0 | 1,889 | 10/23/2020 |
8.4.0 | 5,469 | 10/13/2020 |
8.3.1 | 2,624 | 10/5/2020 |
8.3.0 | 1,278 | 10/3/2020 |
8.2.2 | 2,031 | 9/26/2020 |
8.2.1 | 1,356 | 9/25/2020 |
8.2.0 | 1,376 | 9/25/2020 |
8.1.17 | 6,567 | 9/13/2020 |
8.1.16 | 643 | 9/13/2020 |
8.1.15 | 1,882 | 9/12/2020 |
8.1.11 | 2,474 | 9/11/2020 |
8.1.10 | 1,290 | 9/6/2020 |
8.1.9 | 1,314 | 9/3/2020 |
8.1.8 | 1,319 | 9/2/2020 |