CropResistantCache class
LRU cache keyed by BlockPerceptualHash. Same shape as PerceptualCache but resilient to crops — ideal for forwarded-image moderation where the same content reappears with different framing.
Trade-off: lookups are O(n × gridSize²) where n is the cache
size — roughly 16× slower than PerceptualCache at default settings.
Use PerceptualCache when you control framing; reach for
CropResistantCache when content arrives from social-sharing pipelines.
final cache = NsfwDetector.instance.cropResistantCache;
final cached = await cache.lookup(bytes);
if (cached != null) return cached;
final result = await NsfwDetector.instance.scanBytes(bytes);
await cache.remember(bytes, result);
Constructors
- CropResistantCache({int capacity = 256, int gridSize = BlockPerceptualHash.defaultGridSize, int defaultMinMatchingBlocks = 6, int defaultBlockTolerance = 8})
Properties
- capacity → int
-
Maximum entries retained before LRU eviction.
final
- defaultBlockTolerance → int
-
Default per-block Hamming-distance tolerance.
final
- defaultMinMatchingBlocks → int
-
Default minimum block match count required for lookup to return a hit.
final
- gridSize → int
-
Grid size used when hashing inputs via lookup / remember.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- length → int
-
Number of entries currently in the cache.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
clear(
) → void - Drops every cached entry.
-
lookup(
Uint8List bytes, {int? minMatchingBlocks, int? blockTolerance}) → Future< ScanResult?> -
Looks up
bytes. Returns the first stored result whose hash matches at leastminMatchingBlocksblocks withinblockTolerancebits — promoted to MRU on hit. Returnsnullon miss or hash failure. -
lookupByHash(
BlockPerceptualHash hash, {int? minMatchingBlocks, int? blockTolerance}) → ScanResult? - Variant of lookup for callers that already computed the hash.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
remember(
Uint8List bytes, ScanResult result) → Future< void> -
Stores
resultkeyed by the block-hash ofbytes. No-op on hash failure. -
rememberByHash(
BlockPerceptualHash hash, ScanResult result) → void - Variant of remember for callers that already computed the hash.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited