Skip to content

Commit 2cf586e

Browse files
New cache.
1 parent 24f3b4a commit 2cf586e

File tree

18 files changed

+3965
-335
lines changed

18 files changed

+3965
-335
lines changed

UpgradeLog.htm

Lines changed: 0 additions & 284 deletions
This file was deleted.

sample/Sample.Android/Resources/Resource.designer.cs

Lines changed: 3605 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sample/Sample.Android/Sample.Android.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
</ItemGroup>
6767
<ItemGroup>
6868
<PackageReference Include="Prism.DryIoc.Forms">
69-
<Version>8.0.0.1909</Version>
69+
<Version>8.1.97</Version>
7070
</PackageReference>
7171
<PackageReference Include="RefactoringEssentials">
7272
<Version>5.6.0</Version>
@@ -87,8 +87,8 @@
8787
<PackageReference Include="Xamarin.Firebase.Common">
8888
<Version>120.0.0.5</Version>
8989
</PackageReference>
90-
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2515" />
91-
<PackageReference Include="Xamarin.Essentials" Version="1.6.1" />
90+
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2545" />
91+
<PackageReference Include="Xamarin.Essentials" Version="1.7.4" />
9292
</ItemGroup>
9393
<ItemGroup>
9494
<Compile Include="MainActivity.cs" />

sample/Sample.iOS.Shared/Sample.iOS.Shared.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
</ProjectReference>
5151
</ItemGroup>
5252
<ItemGroup>
53-
<PackageReference Include="Notifo.SDK" Version="1.6.4" />
53+
<PackageReference Include="Notifo.SDK" Version="1.7.3" />
5454
</ItemGroup>
5555
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
5656
</Project>

sample/Sample.iOS/Sample.iOS.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
5353
<MtouchLink>None</MtouchLink>
5454
<MtouchInterpreter>-all</MtouchInterpreter>
55-
<CodesignProvision></CodesignProvision>
55+
<CodesignProvision>
56+
</CodesignProvision>
5657
</PropertyGroup>
5758
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
5859
<DebugType>none</DebugType>
@@ -138,7 +139,7 @@
138139
</ItemGroup>
139140
<ItemGroup>
140141
<PackageReference Include="Prism.DryIoc.Forms">
141-
<Version>8.0.0.1909</Version>
142+
<Version>8.1.97</Version>
142143
</PackageReference>
143144
<PackageReference Include="RefactoringEssentials">
144145
<Version>5.6.0</Version>
@@ -153,8 +154,8 @@
153154
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
154155
<PrivateAssets>all</PrivateAssets>
155156
</PackageReference>
156-
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2515" />
157-
<PackageReference Include="Xamarin.Essentials" Version="1.6.1" />
157+
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2545" />
158+
<PackageReference Include="Xamarin.Essentials" Version="1.7.4" />
158159
</ItemGroup>
159160
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
160161
<ItemGroup>

sample/Sample/Sample.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</ItemGroup>
2020

2121
<ItemGroup>
22-
<PackageReference Include="Prism.DryIoc.Forms" Version="8.0.0.1909" />
22+
<PackageReference Include="Prism.DryIoc.Forms" Version="8.1.97" />
2323
<PackageReference Include="RefactoringEssentials" Version="5.6.0">
2424
<PrivateAssets>all</PrivateAssets>
2525
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -29,8 +29,8 @@
2929
<PrivateAssets>all</PrivateAssets>
3030
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3131
</PackageReference>
32-
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2515" />
33-
<PackageReference Include="Xamarin.Essentials" Version="1.6.1" />
32+
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2545" />
33+
<PackageReference Include="Xamarin.Essentials" Version="1.7.4" />
3434
</ItemGroup>
3535

3636
<ItemGroup>

sample/SampleNotificationServiceExtension/SampleNotificationServiceExtension.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@
8888
</PropertyGroup>
8989
<ItemGroup>
9090
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
91-
<HintPath>..\..\packages\Newtonsoft.Json.13.0.1\lib\netstandard2.0\Newtonsoft.Json.dll</HintPath>
91+
<HintPath>..\..\packages\Newtonsoft.Json.13.0.2\lib\netstandard2.0\Newtonsoft.Json.dll</HintPath>
9292
</Reference>
93-
<Reference Include="Notifo.SDK, Version=1.7.0.0, Culture=neutral, processorArchitecture=MSIL">
94-
<HintPath>..\..\packages\Notifo.SDK.1.7.0\lib\netstandard2.1\Notifo.SDK.dll</HintPath>
93+
<Reference Include="Notifo.SDK, Version=1.7.3.0, Culture=neutral, processorArchitecture=MSIL">
94+
<HintPath>..\..\packages\Notifo.SDK.1.7.3\lib\netstandard2.1\Notifo.SDK.dll</HintPath>
9595
</Reference>
9696
<Reference Include="System" />
9797
<Reference Include="System.Xml" />
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="xamarinios10" />
4-
<package id="Notifo.SDK" version="1.7.0" targetFramework="xamarinios10" />
3+
<package id="Newtonsoft.Json" version="13.0.2" targetFramework="xamarinios10" />
4+
<package id="Notifo.SDK" version="1.7.3" targetFramework="xamarinios10" />
55
<package id="System.ComponentModel.Annotations" version="5.0.0" targetFramework="xamarinios10" />
66
</packages>

sdk/Notifo.SDK.FirebasePlugin/Notifo.SDK.FirebasePlugin.csproj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
<None Include="**\*.android.cs" />
4242
</ItemGroup>
4343

44+
<ItemGroup>
45+
<PackageReference Include="Notifo.SDK" Version="1.7.3" />
46+
</ItemGroup>
47+
4448
<ItemGroup Condition="$(TargetFramework.StartsWith('xamarinios'))">
4549
<PackageReference Include="Xamarin.Firebase.iOS.CloudMessaging" Version="8.10.0.1" />
4650
<PackageReference Include="Xamarin.Firebase.iOS.Installations" Version="8.10.0.1" />
@@ -53,11 +57,6 @@
5357
<PackageReference Include="Xamarin.Firebase.Messaging" Version="122.0.0.5" />
5458
</ItemGroup>
5559

56-
<ItemGroup>
57-
<PackageReference Include="Notifo.SDK" Version="1.6.4" />
58-
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="5.0.0" />
59-
</ItemGroup>
60-
6160
<ItemGroup>
6261
<ProjectReference Include="..\Notifo.SDK\Notifo.SDK.Core.csproj" />
6362
</ItemGroup>

sdk/Notifo.SDK/Helpers/LRUCache.cs

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
// ==========================================================================
2+
// Notifo.io
3+
// ==========================================================================
4+
// Copyright (c) Sebastian Stehle
5+
// All rights reserved. Licensed under the MIT license.
6+
// ==========================================================================
7+
8+
using System;
9+
using System.Collections.Generic;
10+
using System.Diagnostics.CodeAnalysis;
11+
12+
namespace Notifo.SDK.Helpers
13+
{
14+
internal sealed class LRUCache<TKey, TValue> where TKey : notnull
15+
{
16+
private readonly Dictionary<TKey, LinkedListNode<LRUCacheItem<TKey, TValue>>> cacheMap = new Dictionary<TKey, LinkedListNode<LRUCacheItem<TKey, TValue>>>();
17+
private readonly LinkedList<LRUCacheItem<TKey, TValue>> cacheHistory = new LinkedList<LRUCacheItem<TKey, TValue>>();
18+
private int totalCapacity;
19+
private int totalSize;
20+
21+
public int Size => totalSize;
22+
23+
public LRUCache(int capacity)
24+
{
25+
EnsureCapacity(capacity);
26+
}
27+
28+
public void EnsureCapacity(int capacity)
29+
{
30+
if (capacity <= 0)
31+
{
32+
throw new ArgumentException("Capacity must be positive.", nameof(capacity));
33+
}
34+
35+
lock (cacheMap)
36+
{
37+
while (totalCapacity > capacity)
38+
{
39+
RemoveFirst();
40+
}
41+
42+
totalCapacity = capacity;
43+
}
44+
}
45+
46+
public void Clear()
47+
{
48+
lock (cacheMap)
49+
{
50+
cacheHistory.Clear();
51+
cacheMap.Clear();
52+
53+
totalSize = 0;
54+
}
55+
}
56+
57+
public bool Set(TKey key, TValue value, int size = 1)
58+
{
59+
lock (cacheMap)
60+
{
61+
if (cacheMap.TryGetValue(key, out var node))
62+
{
63+
node.Value.Value = value;
64+
65+
cacheHistory.Remove(node);
66+
cacheHistory.AddLast(node);
67+
68+
cacheMap[key] = node;
69+
70+
return true;
71+
}
72+
73+
totalSize += size;
74+
75+
if (totalSize > totalCapacity)
76+
{
77+
RemoveFirst();
78+
}
79+
80+
var cacheItem = new LRUCacheItem<TKey, TValue> { Key = key, Value = value, Size = size };
81+
82+
node = new LinkedListNode<LRUCacheItem<TKey, TValue>>(cacheItem);
83+
84+
cacheMap.Add(key, node);
85+
cacheHistory.AddLast(node);
86+
87+
return false;
88+
}
89+
}
90+
91+
public bool Remove(TKey key)
92+
{
93+
lock (cacheMap)
94+
{
95+
if (cacheMap.TryGetValue(key, out var node))
96+
{
97+
cacheMap.Remove(key);
98+
cacheHistory.Remove(node);
99+
100+
return true;
101+
}
102+
103+
return false;
104+
}
105+
}
106+
107+
public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
108+
{
109+
lock (cacheMap)
110+
{
111+
value = default!;
112+
113+
if (cacheMap.TryGetValue(key, out var node))
114+
{
115+
value = node.Value.Value;
116+
117+
cacheHistory.Remove(node);
118+
cacheHistory.AddLast(node);
119+
120+
return true;
121+
}
122+
123+
return false;
124+
}
125+
}
126+
127+
public bool Contains(TKey key)
128+
{
129+
lock (cacheMap)
130+
{
131+
return cacheMap.ContainsKey(key);
132+
}
133+
}
134+
135+
private void RemoveFirst()
136+
{
137+
var node = cacheHistory.First;
138+
139+
if (node != null)
140+
{
141+
cacheMap.Remove(node.Value.Key);
142+
cacheHistory.RemoveFirst();
143+
144+
totalSize -= node.Value.Size;
145+
}
146+
}
147+
}
148+
}

0 commit comments

Comments
 (0)