public async Task <ICrawlerResultSingle <T> > CrawlById(string id) { if (Cache.IsCached(id)) { return(CrawlerResultBase <T> .FromCache(Cache.Get(id))); } try { var source = await Source.ObtainSource(id); var result = await Parser.ParseDetail(source, id); Cache.Set(result.Result, id); return(result); } catch (Exception e) { return(new CrawlerResultBase <T> { Success = false }); } }
public virtual async Task <ICrawlerResultList <T> > Crawl( CrawlerParameters parameters, CancellationToken token) { if (parameters.VolatileParameters.UseCache && Cache.IsCached(parameters)) { return(CrawlerResultBase <T> .FromCache(Cache.Get(parameters))); } try { var source = await Source.ObtainSource(parameters, token); var result = await Parser.Parse(source, parameters); Cache.Set(result.Results, parameters); return(result); } catch (Exception e) { return(new CrawlerResultBase <T> { Success = false }); } }