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 | 514 | 1/22/2024 |
17.1.7 | 239 | 1/12/2024 |
17.1.6 | 210 | 1/11/2024 |
17.1.5 | 223 | 1/5/2024 |
17.0.1 | 273 | 1/1/2024 |
17.0.0 | 414 | 12/14/2023 |
16.11.5 | 429 | 11/12/2023 |
16.9.0 | 435 | 10/9/2023 |
16.7.0 | 653 | 7/11/2023 |
16.4.1 | 497 | 7/2/2023 |
16.4.0 | 479 | 6/22/2023 |
16.3.1 | 457 | 6/7/2023 |
16.3.0 | 427 | 5/28/2023 |
16.1.9 | 762 | 4/30/2023 |
15.10.11 | 614 | 4/13/2023 |
15.9.1 | 742 | 3/26/2023 |
15.9.0 | 613 | 3/24/2023 |
15.8.2 | 707 | 3/20/2023 |
15.7.0 | 592 | 3/6/2023 |
15.5.0 | 1,997 | 1/28/2023 |
15.2.0 | 1,058 | 1/18/2023 |
15.1.0 | 1,544 | 12/28/2022 |
14.5.7 | 1,118 | 12/13/2022 |
14.5.5 | 1,229 | 12/6/2022 |
14.5.1 | 1,117 | 11/23/2022 |
14.5.0 | 1,104 | 11/18/2022 |
14.4.5 | 1,264 | 10/22/2022 |
14.4.1 | 1,291 | 10/22/2022 |
14.4.0 | 1,193 | 10/17/2022 |
14.3.1 | 1,858 | 9/12/2022 |
14.3.0 | 1,220 | 9/10/2022 |
14.1.3 | 1,531 | 8/7/2022 |
14.1.2 | 1,238 | 8/7/2022 |
14.1.1 | 1,258 | 8/7/2022 |
14.0.14 | 1,317 | 7/26/2022 |
14.0.12 | 1,286 | 7/24/2022 |
14.0.11 | 1,200 | 7/23/2022 |
14.0.10 | 1,200 | 7/23/2022 |
14.0.9 | 1,229 | 7/23/2022 |
14.0.8 | 1,352 | 7/17/2022 |
14.0.5 | 1,390 | 7/11/2022 |
14.0.4 | 1,426 | 7/6/2022 |
14.0.3 | 1,311 | 7/2/2022 |
14.0.2 | 1,242 | 7/2/2022 |
14.0.0 | 1,735 | 6/25/2022 |
13.4.0 | 2,627 | 5/31/2022 |
13.3.4 | 2,020 | 5/9/2022 |
13.3.0 | 1,786 | 5/1/2022 |
13.2.0 | 1,828 | 4/21/2022 |
13.1.0 | 1,676 | 4/7/2022 |
13.0.0 | 1,329 | 4/5/2022 |
11.0.5 | 2,342 | 3/2/2022 |
11.0.4 | 1,357 | 2/22/2022 |
11.0.3 | 1,390 | 2/9/2022 |
11.0.2 | 1,413 | 2/6/2022 |
11.0.1 | 538 | 2/5/2022 |
11.0.0 | 1,432 | 2/5/2022 |
10.0.21 | 1,402 | 1/28/2022 |
10.0.20 | 1,070 | 1/27/2022 |
10.0.19 | 1,095 | 1/23/2022 |
10.0.18 | 1,046 | 1/17/2022 |
10.0.15 | 1,182 | 12/31/2021 |
10.0.14 | 809 | 12/28/2021 |
10.0.8 | 1,438 | 12/22/2021 |
10.0.7 | 762 | 12/22/2021 |
10.0.5 | 742 | 12/18/2021 |
9.9.9 | 1,698 | 11/29/2021 |
9.9.3 | 908 | 11/9/2021 |
9.9.2 | 614 | 11/4/2021 |
9.9.0 | 746 | 10/30/2021 |
9.8.9 | 714 | 10/29/2021 |
9.8.7 | 685 | 10/27/2021 |
9.8.6 | 640 | 10/27/2021 |
9.8.5 | 715 | 10/26/2021 |
9.8.0 | 1,383 | 10/20/2021 |
9.7.9 | 666 | 10/19/2021 |
9.7.5 | 1,482 | 10/14/2021 |
9.7.0 | 864 | 10/9/2021 |
9.6.6 | 1,237 | 8/14/2021 |
9.2.0 | 6,232 | 5/26/2021 |
9.1.4 | 1,275 | 4/21/2021 |
9.1.0 | 1,071 | 4/14/2021 |
9.0.0 | 836 | 4/5/2021 |
8.9.9 | 1,006 | 3/30/2021 |
8.9.3 | 1,540 | 3/19/2021 |
8.9.2 | 1,039 | 1/29/2021 |
8.9.1 | 1,020 | 1/24/2021 |
8.9.0 | 1,117 | 1/22/2021 |
8.6.9 | 2,925 | 11/8/2020 |
8.6.6 | 1,943 | 11/2/2020 |
8.6.2 | 2,566 | 10/30/2020 |
8.6.0 | 2,010 | 10/28/2020 |
8.5.0 | 1,885 | 10/23/2020 |
8.4.0 | 5,465 | 10/13/2020 |
8.3.1 | 2,620 | 10/5/2020 |
8.3.0 | 1,274 | 10/3/2020 |
8.2.2 | 2,027 | 9/26/2020 |
8.2.1 | 1,352 | 9/25/2020 |
8.2.0 | 1,372 | 9/25/2020 |
8.1.17 | 6,563 | 9/13/2020 |
8.1.16 | 639 | 9/13/2020 |
8.1.15 | 1,878 | 9/12/2020 |
8.1.11 | 2,470 | 9/11/2020 |
8.1.10 | 1,286 | 9/6/2020 |
8.1.9 | 1,310 | 9/3/2020 |
8.1.8 | 1,315 | 9/2/2020 |