Skip to content

Commit

Permalink
Updated SQL.cs to use V3.2 code.
Browse files Browse the repository at this point in the history
In particular the change concerns the way cache is used in V3.2. This
change addresses the build errors.


Former-commit-id: 037e71d8d9081d9328ec5225a54282e973908fdc
  • Loading branch information
Mike committed Sep 30, 2015
1 parent 48b5de6 commit a0e9fd8
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions FoundationV3/Mobile/Detection/SQL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using System.Collections.Generic;
using System.Linq;
using FiftyOne.Foundation.Mobile.Detection.Entities;
using System.Threading;

namespace FiftyOne.Foundation.Mobile.Detection
{
Expand Down Expand Up @@ -278,16 +279,19 @@ private static InternalResult GetMatch(IEnumerator<int> iterator)
private static InternalResult GetMatchById(string id)
{
InternalResult result;
if (_cacheUserAgent.TryGetValue(id, out result) == false)
if (_cacheUserAgent._itemsActive.TryGetValue(id, out result) == false)
{
result = GetMatch(IterateProfileIds(id));

// Add the results to the cache.
_cacheUserAgent.SetActive(id, result);
_cacheUserAgent._itemsActive[id] = result;

Interlocked.Increment(ref _cacheUserAgent.Misses);
}

// Ensure the result is added to the background cache.
_cacheUserAgent.SetBackground(id, result);
//_cacheUserAgent.SetBackground(id, result);
_cacheUserAgent.AddRecent(id, result);

return result;
}
Expand All @@ -303,16 +307,19 @@ private static InternalResult GetMatchById(string id)
private static InternalResult GetMatchById(byte[] id)
{
InternalResult result;
if (_cacheId.TryGetValue(id, out result) == false)
if (_cacheId._itemsActive.TryGetValue(id, out result) == false)
{
result = GetMatch(IterateProfileIds(id));

// Add the results to the cache.
_cacheId.SetActive(id, result);
_cacheId._itemsActive[id] = result;

Interlocked.Increment(ref _cacheId.Misses);
}

// Ensure the result is added to the background cache.
_cacheId.SetBackground(id, result);
//_cacheId.SetBackground(id, result);
_cacheId.AddRecent(id, result);

return result;
}
Expand All @@ -326,7 +333,7 @@ private static InternalResult GetMatchById(byte[] id)
private static InternalResult GetMatchByUserAgent(string userAgent)
{
InternalResult result;
if (_cacheUserAgent.TryGetValue(userAgent, out result) == false)
if (_cacheUserAgent._itemsActive.TryGetValue(userAgent, out result) == false)
{
// The result wasn't in the cache so find it from the 51Degrees provider.
var match = _provider.Match(userAgent);
Expand Down Expand Up @@ -371,11 +378,12 @@ private static InternalResult GetMatchByUserAgent(string userAgent)
}

// Add the results to the cache.
_cacheUserAgent.SetActive(userAgent, result);
_cacheUserAgent._itemsActive[userAgent] = result;
}

// Ensure the result is added to the background cache.
_cacheUserAgent.SetBackground(userAgent, result);
//_cacheUserAgent.SetBackground(userAgent, result);
_cacheUserAgent.AddRecent(userAgent, result);

return result;
}
Expand Down Expand Up @@ -442,10 +450,13 @@ public static SqlBoolean InitialiseDeviceDetection(SqlString filename, SqlString
if (_provider != null)
{
// Clear the caches to flush out old results.
/*
var serviceInternal = expirySeconds.IsNull ?
DEFAULT_CACHE_EXPIRY_SECONDS : expirySeconds.Value;
_cacheUserAgent = new Cache<string, InternalResult>(serviceInternal);
_cacheId = new Cache<byte[], InternalResult>(new ByteArrayEqualityComparer(), serviceInternal);
* */
int cacheSize = 1000;
_cacheUserAgent = new Cache<string, InternalResult>(cacheSize);
_cacheId = new Cache<byte[], InternalResult>(cacheSize);

// Set the properties that the functions should be returning.
_numberOfProperties = 0;
Expand Down

0 comments on commit a0e9fd8

Please sign in to comment.