Skip to content

CacheItemPriority.NotRemovable is not honored(?) in net core with FileCacheManagers.Hashed #38

Description

@andrvo

I'm trying to use FileCache in a net core project to store some intermediate data between several console app launches. Here is a sample.

`
FileCache.DefaultCacheManager = FileCacheManagers.Hashed;
var fc = new FileCache(@"c:\temp\testcache");
string key = "a1:Settings";

        var v = fc.Get(key);
        if (v != null)
            Console.WriteLine($"Cached item: {v}");
        else
            Console.WriteLine("Cached item not found");

        var itemPolicy = new CacheItemPolicy
        {
            AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(10),
            Priority = CacheItemPriority.NotRemovable
        };
        if (fc.Add(key, "some string value", itemPolicy))
            Console.WriteLine("Cached item added");
        else
            Console.WriteLine("---- Failed to add the item to the cache ----");

        var v2 = fc.Get(key);
        if (v2 != null)
            Console.WriteLine($"Cached item: {v2}");
        else
            Console.WriteLine("Cached item not found");

`

In a net core console app the first Get return null always. The second Get returns the test value.

It works as expected in a .NET Framework project. The first Get returns the cached value on the second app launch.
AND it works as expected without the first line (FileCache.DefaultCacheManager = FileCacheManagers.Hashed;)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions