magic.lambda.caching 14.3.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package magic.lambda.caching --version 14.3.0                
NuGet\Install-Package magic.lambda.caching -Version 14.3.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="14.3.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add magic.lambda.caching --version 14.3.0                
#r "nuget: magic.lambda.caching, 14.3.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=14.3.0

// Install magic.lambda.caching as a Cake Tool
#tool nuget:?package=magic.lambda.caching&version=14.3.0                

Caching with Magic and Hyperlambda

Cache helper slots for Magic. 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.

[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

[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

[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.

[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.

[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".

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.

Quality gates

  • Build status
  • Quality Gate Status
  • Bugs
  • Code Smells
  • Coverage
  • Duplicated Lines (%)
  • Lines of Code
  • Maintainability Rating
  • Reliability Rating
  • Security Rating
  • Technical Debt
  • Vulnerabilities
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 528 1/22/2024
17.1.7 246 1/12/2024
17.1.6 217 1/11/2024
17.1.5 236 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 597 3/6/2023
15.5.0 2,001 1/28/2023
15.2.0 1,062 1/18/2023
15.1.0 1,554 12/28/2022
14.5.7 1,122 12/13/2022
14.5.5 1,235 12/6/2022
14.5.1 1,123 11/23/2022
14.5.0 1,110 11/18/2022
14.4.5 1,271 10/22/2022
14.4.1 1,297 10/22/2022
14.4.0 1,199 10/17/2022
14.3.1 1,866 9/12/2022
14.3.0 1,226 9/10/2022
14.1.3 1,537 8/7/2022
14.1.2 1,244 8/7/2022
14.1.1 1,264 8/7/2022
14.0.14 1,323 7/26/2022
14.0.12 1,293 7/24/2022
14.0.11 1,206 7/23/2022
14.0.10 1,206 7/23/2022
14.0.9 1,236 7/23/2022
14.0.8 1,358 7/17/2022
14.0.5 1,396 7/11/2022
14.0.4 1,432 7/6/2022
14.0.3 1,317 7/2/2022
14.0.2 1,248 7/2/2022
14.0.0 1,741 6/25/2022
13.4.0 2,635 5/31/2022
13.3.4 2,026 5/9/2022
13.3.0 1,792 5/1/2022
13.2.0 1,834 4/21/2022
13.1.0 1,682 4/7/2022
13.0.0 1,340 4/5/2022
11.0.5 2,348 3/2/2022
11.0.4 1,363 2/22/2022
11.0.3 1,401 2/9/2022
11.0.2 1,419 2/6/2022
11.0.1 544 2/5/2022
11.0.0 1,444 2/5/2022
10.0.21 1,408 1/28/2022
10.0.20 1,076 1/27/2022
10.0.19 1,101 1/23/2022
10.0.18 1,052 1/17/2022
10.0.15 1,188 12/31/2021
10.0.14 815 12/28/2021
10.0.8 1,444 12/22/2021
10.0.7 768 12/22/2021
10.0.5 748 12/18/2021
9.9.9 1,704 11/29/2021
9.9.3 914 11/9/2021
9.9.2 622 11/4/2021
9.9.0 752 10/30/2021
9.8.9 720 10/29/2021
9.8.7 691 10/27/2021
9.8.6 651 10/27/2021
9.8.5 721 10/26/2021
9.8.0 1,389 10/20/2021
9.7.9 672 10/19/2021
9.7.5 1,488 10/14/2021
9.7.0 877 10/9/2021
9.6.6 1,243 8/14/2021
9.2.0 6,238 5/26/2021
9.1.4 1,282 4/21/2021
9.1.0 1,078 4/14/2021
9.0.0 842 4/5/2021
8.9.9 1,015 3/30/2021
8.9.3 1,546 3/19/2021
8.9.2 1,045 1/29/2021
8.9.1 1,026 1/24/2021
8.9.0 1,123 1/22/2021
8.6.9 2,931 11/8/2020
8.6.6 1,950 11/2/2020
8.6.2 2,572 10/30/2020
8.6.0 2,018 10/28/2020
8.5.0 1,891 10/23/2020
8.4.0 5,471 10/13/2020
8.3.1 2,626 10/5/2020
8.3.0 1,280 10/3/2020
8.2.2 2,033 9/26/2020
8.2.1 1,358 9/25/2020
8.2.0 1,378 9/25/2020
8.1.17 6,569 9/13/2020
8.1.16 646 9/13/2020
8.1.15 1,884 9/12/2020
8.1.11 2,476 9/11/2020
8.1.10 1,292 9/6/2020
8.1.9 1,316 9/3/2020
8.1.8 1,321 9/2/2020