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
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="magic.lambda.caching" Version="17.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add magic.lambda.caching --version 17.2.0
#r "nuget: magic.lambda.caching, 17.2.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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.

  • Build status
  • Quality Gate Status
  • Bugs
  • Code Smells
  • Coverage
  • Duplicated Lines (%)
  • Lines of Code
  • Maintainability Rating
  • Reliability Rating
  • Security Rating
  • Technical Debt
  • Vulnerabilities

The projects is copyright Thomas Hansen 2023 - 2024, and professionally maintained by AINIRO.IO.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 317 1/22/2024
17.1.7 181 1/12/2024
17.1.6 157 1/11/2024
17.1.5 168 1/5/2024
17.0.1 208 1/1/2024
17.0.0 358 12/14/2023
16.11.5 361 11/12/2023
16.9.0 375 10/9/2023
16.7.0 574 7/11/2023
16.4.1 419 7/2/2023
16.4.0 412 6/22/2023
16.3.1 412 6/7/2023
16.3.0 382 5/28/2023
16.1.9 702 4/30/2023
15.10.11 559 4/13/2023
15.9.1 700 3/26/2023
15.9.0 568 3/24/2023
15.8.2 651 3/20/2023
15.7.0 549 3/6/2023
15.5.0 1,875 1/28/2023
15.2.0 979 1/18/2023
15.1.0 1,479 12/28/2022
14.5.7 1,046 12/13/2022
14.5.5 1,151 12/6/2022
14.5.1 1,066 11/23/2022
14.5.0 1,034 11/18/2022
14.4.5 1,189 10/22/2022
14.4.1 1,220 10/22/2022
14.4.0 1,116 10/17/2022
14.3.1 1,783 9/12/2022
14.3.0 1,159 9/10/2022
14.1.3 1,472 8/7/2022
14.1.2 1,171 8/7/2022
14.1.1 1,198 8/7/2022
14.0.14 1,243 7/26/2022
14.0.12 1,223 7/24/2022
14.0.11 1,156 7/23/2022
14.0.10 1,144 7/23/2022
14.0.9 1,167 7/23/2022
14.0.8 1,289 7/17/2022
14.0.5 1,325 7/11/2022
14.0.4 1,370 7/6/2022
14.0.3 1,255 7/2/2022
14.0.2 1,180 7/2/2022
14.0.0 1,649 6/25/2022
13.4.0 2,553 5/31/2022
13.3.4 1,945 5/9/2022
13.3.0 1,707 5/1/2022
13.2.0 1,761 4/21/2022
13.1.0 1,612 4/7/2022
13.0.0 1,269 4/5/2022
11.0.5 2,254 3/2/2022
11.0.4 1,305 2/22/2022
11.0.3 1,332 2/9/2022
11.0.2 1,355 2/6/2022
11.0.1 511 2/5/2022
11.0.0 1,372 2/5/2022
10.0.21 1,340 1/28/2022
10.0.20 1,026 1/27/2022
10.0.19 1,042 1/23/2022
10.0.18 1,000 1/17/2022
10.0.15 1,121 12/31/2021
10.0.14 767 12/28/2021
10.0.8 1,366 12/22/2021
10.0.7 721 12/22/2021
10.0.5 709 12/18/2021
9.9.9 1,639 11/29/2021
9.9.3 861 11/9/2021
9.9.2 592 11/4/2021
9.9.0 706 10/30/2021
9.8.9 684 10/29/2021
9.8.7 645 10/27/2021
9.8.6 601 10/27/2021
9.8.5 687 10/26/2021
9.8.0 1,328 10/20/2021
9.7.9 636 10/19/2021
9.7.5 1,431 10/14/2021
9.7.0 828 10/9/2021
9.6.6 1,180 8/14/2021
9.2.0 6,088 5/26/2021
9.1.4 1,229 4/21/2021
9.1.0 1,022 4/14/2021
9.0.0 800 4/5/2021
8.9.9 979 3/30/2021
8.9.3 1,489 3/19/2021
8.9.2 998 1/29/2021
8.9.1 987 1/24/2021
8.9.0 1,088 1/22/2021
8.6.9 2,881 11/8/2020
8.6.6 1,913 11/2/2020
8.6.2 2,529 10/30/2020
8.6.0 1,961 10/28/2020
8.5.0 1,844 10/23/2020
8.4.0 5,392 10/13/2020
8.3.1 2,573 10/5/2020
8.3.0 1,236 10/3/2020
8.2.2 1,982 9/26/2020
8.2.1 1,321 9/25/2020
8.2.0 1,342 9/25/2020
8.1.17 6,502 9/13/2020
8.1.16 612 9/13/2020
8.1.15 1,826 9/12/2020
8.1.11 2,425 9/11/2020
8.1.10 1,251 9/6/2020
8.1.9 1,279 9/3/2020
8.1.8 1,285 9/2/2020