Files
Jackett-Jackett/src/Jackett.Test/TestHelpers/TestWebIndexer.cs
Diego Heras 69125add3e core: redo search cache from scratch. resolves #10382 (#10447)
In simple words, when you make a request in Jackett, the results are saved in memory (cache). The next request will return results form the cache improving response time and making fewer requests to the sites.
* We assume all indexers/sites are stateless, the same request return the same response. If you change the search term, categories or something in the query Jackett has to make a live request to the indexer.
* There are some situations when we don't want to use the cache:
** When we are testing the indexers => if query.IsTest results are not cached
** When the user updates the configuration of one indexer => We call CleanIndexerCache to remove cached results before testing the configuration
** When there is some error/exception in the indexer => The results are not cached so we can retry in the next request
* We want to limit the memory usage, so we try to remove elements from cache ASAP:
** Each indexer can have a maximum number of results in memory. If the limit is exceeded we remove old results
** Cached results expire after some time
* Users can configure the cache or even disable it
2020-12-11 23:14:21 +01:00

82 lines
3.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Jackett.Common.Indexers;
using Jackett.Common.Models;
using Jackett.Common.Models.IndexerConfig;
using Newtonsoft.Json.Linq;
namespace Jackett.Test.TestHelpers
{
public class TestWebIndexer: BaseWebIndexer
{
public TestWebIndexer():
base(id: "test_id",
name: "test_name",
description: "test_description",
link: "https://test.link/",
caps: new TorznabCapabilities(),
client: null,
configService: null,
logger: null,
configData: new ConfigurationData(),
p: null,
cacheService: null)
{
Encoding = Encoding.UTF8;
Language = "en-us";
Type = "private";
}
public override string[] AlternativeSiteLinks { get; protected set; } = {
"https://test.link/",
"https://alternative-test.link/"
};
public override string[] LegacySiteLinks { get; protected set; } = {
"https://legacy-test.link/"
};
public override Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson) =>
throw new NotImplementedException();
protected override Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query) =>
throw new NotImplementedException();
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// public methods to test private methods
public void SetType(string type) => Type = type;
public IEnumerable<ReleaseInfo> _FilterResults(TorznabQuery query, IEnumerable<ReleaseInfo> results) =>
FilterResults(query, results);
public IEnumerable<ReleaseInfo> _FixResults(TorznabQuery query, IEnumerable<ReleaseInfo> results) =>
FixResults(query, results);
public void _AddCategoryMapping(string trackerCategory, TorznabCategory newznabCategory, string trackerCategoryDesc = null) =>
AddCategoryMapping(trackerCategory, newznabCategory, trackerCategoryDesc);
public void _AddCategoryMapping(int trackerCategory, TorznabCategory newznabCategory, string trackerCategoryDesc = null) =>
AddCategoryMapping(trackerCategory, newznabCategory, trackerCategoryDesc);
public void _AddMultiCategoryMapping(TorznabCategory newznabCategory, params int[] trackerCategories) =>
AddMultiCategoryMapping(newznabCategory, trackerCategories);
public List<string> _MapTorznabCapsToTrackers(TorznabQuery query, bool mapChildrenCatsToParent = false) =>
MapTorznabCapsToTrackers(query, mapChildrenCatsToParent);
public ICollection<int> _MapTrackerCatToNewznab(string input) =>
MapTrackerCatToNewznab(input);
public ICollection<int> _MapTrackerCatDescToNewznab(string input) =>
MapTrackerCatDescToNewznab(input);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// public methods to load sample datasets
public void AddTestCategories()
{
TestCategories.AddTestCategories(TorznabCaps.Categories);
}
}
}