totpero / DeviceDetector.NET

The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.
Apache License 2.0
347 stars 73 forks source link

Slow requests #27

Open efraimt opened 4 years ago

efraimt commented 4 years ago

Hi,

First of all I appreciate the amazing work that you did and gave the community for no profit.

Sadly, I don't have right now the ability to write some code that will do some improvements myself :( I was wondering if the .NET version uses any cache system, queries are really slow even on strong servers. I also was wondering if there is a way to write code that will get every time the updated YML's?

Thanks again

totpero commented 4 years ago

Hi @efraimt thanks for your feedback, In this project is implemented static Dictionary cache, you can use it like this:

var dd = new DeviceDetector(userAgent);

// OPTIONAL: Set caching method
// By default static cache is used, which works best within one php process (memory array caching)
// To cache across requests use caching in files or memcache
// add using DeviceDetectorNET.Cache;
dd.SetCache(new DictionaryCache());

But can be created other cache implementation like redis cache.

The YAML file is embeded in project but if you want to update manually the yaml files from the original php repo you can use static location like this: DeviceDetectorSettings.RegexesDirectory = @"C:\YamlRegexsFiles\"; And there you can update your yaml.

I was very busy this time but i will update the project to day; If you want or some one else can create pull request with all update from php repo and i will merge it in this. Thanks

totpero commented 4 years ago

@efraimt Try to use this see if works.

stbentia commented 4 years ago

Hi, I checked in a pull request to add a persistent cache for the results of Parse calls. @efraimt Please see if that helps.

ragasjohn commented 8 months ago

Hello to all, I have the same problem on an .net API I am using. The requests sometimes take 50ms to complete.

I am using it like this

` var userAgent = httpContext.Request.Headers["User-Agent"];//.UserAgent;

var detector = new DeviceDetector(userAgent); detector.Parse();

if (detector.IsBot()) { return "Bot"; // Handle bots separately if needed }

if (detector.IsDesktop()) { return "Desktop"; } else if (detector.IsTablet()) { return "Tablet"; } else if (detector.IsMobile()) { return "Mobile"; } else { return "Unknown"; }`

I do not want to use caching since this it costs more to use it per session. I have millions of request to my API

Any help appreciated

Thanks Yannis