import * as _alepha_core1 from "alepha";
import * as _alepha_core0 from "alepha";
import { Descriptor, InstantiableClass, KIND } from "alepha";
import { DateTimeProvider, DurationLike, Timeout } from "alepha/datetime";

//#region src/providers/CacheProvider.d.ts
/**
 * Cache provider interface.
 *
 * All methods are asynchronous and return promises.
 * Values are stored as Uint8Array.
 */
declare abstract class CacheProvider {
  /**
   * Get the value of a key.
   *
   * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
   * @param key The key of the value to get.
   *
   * @return The value of the key, or undefined if the key does not exist.
   */
  abstract get(name: string, key: string): Promise<Uint8Array | undefined>;
  /**
   * Set the string value of a key.
   *
   * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
   * @param key The key of the value to set.
   * @param value The value to set.
   * @param ttl The time-to-live of the key, in milliseconds.
   *
   * @return The value of the key.
   */
  abstract set(name: string, key: string, value: Uint8Array, ttl?: number): Promise<Uint8Array>;
  /**
   * Remove the specified keys.
   *
   * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
   * @param keys The keys to delete.
   */
  abstract del(name: string, ...keys: string[]): Promise<void>;
  abstract has(name: string, key: string): Promise<boolean>;
  abstract keys(name: string, filter?: string): Promise<string[]>;
}
//# sourceMappingURL=CacheProvider.d.ts.map
//#endregion
//#region src/descriptors/$cache.d.ts
/**
 * Creates a cache storage or a cache function.
 */
declare const $cache: {
  <TReturn = string, TParameter extends any[] = any[]>(options?: CacheDescriptorOptions<TReturn, TParameter>): CacheDescriptorFn<TReturn, TParameter>;
  [KIND]: typeof CacheDescriptor;
};
interface CacheDescriptorOptions<TReturn, TParameter extends any[] = any[]> {
  /**
   * The cache name. This is useful for invalidating multiple caches at once.
   *
   * Store key as `cache:$name:$key`.
   *
   * @default Name of the key of the class.
   */
  name?: string;
  /**
   * Function which returns cached data.
   */
  handler?: (...args: TParameter) => TReturn;
  /**
   * The key generator for the cache.
   * If not provided, the arguments will be json.stringify().
   */
  key?: (...args: TParameter) => string;
  /**
   * The store provider for the cache.
   * If not provided, the default store provider will be used.
   */
  provider?: InstantiableClass<CacheProvider> | "memory";
  /**
   * The time-to-live for the cache in seconds.
   * Set 0 to skip expiration.
   *
   * @default 300 (5 minutes).
   */
  ttl?: DurationLike;
  /**
   * If the cache is disabled.
   */
  disabled?: boolean;
}
declare class CacheDescriptor<TReturn = any, TParameter extends any[] = any[]> extends Descriptor<CacheDescriptorOptions<TReturn, TParameter>> {
  protected readonly env: {
    CACHE_ENABLED: boolean;
    CACHE_DEFAULT_TTL: number;
  };
  protected readonly dateTimeProvider: DateTimeProvider;
  protected readonly provider: CacheProvider;
  protected encoder: TextEncoder;
  protected decoder: TextDecoder;
  protected codes: {
    BINARY: number;
    JSON: number;
    STRING: number;
  };
  get container(): string;
  run(...args: TParameter): Promise<TReturn>;
  key(...args: TParameter): string;
  invalidate(...keys: string[]): Promise<void>;
  set(key: string, value: TReturn, ttl?: DurationLike): Promise<void>;
  get(key: string): Promise<TReturn | undefined>;
  protected serialize<TReturn>(value: TReturn): Uint8Array;
  protected deserialize<TReturn>(uint8Array: Uint8Array): Promise<TReturn>;
  protected $provider(): CacheProvider;
}
interface CacheDescriptorFn<TReturn = any, TParameter extends any[] = any[]> extends CacheDescriptor<TReturn, TParameter> {
  /**
   * Run the cache descriptor with the provided arguments.
   */
  (...args: TParameter): Promise<TReturn>;
}
//# sourceMappingURL=$cache.d.ts.map
//#endregion
//#region src/providers/MemoryCacheProvider.d.ts
type CacheName = string;
type CacheKey = string;
type CacheValue = {
  data?: Uint8Array;
  timeout?: Timeout;
};
declare class MemoryCacheProvider implements CacheProvider {
  protected readonly dateTimeProvider: DateTimeProvider;
  protected readonly log: _alepha_core1.Logger;
  protected store: Record<CacheName, Record<CacheKey, CacheValue>>;
  get(name: string, key: string): Promise<Uint8Array | undefined>;
  set(name: string, key: string, value: Uint8Array, ttl?: number): Promise<Uint8Array>;
  del(name: string, ...keys: string[]): Promise<void>;
  has(name: string, key: string): Promise<boolean>;
  keys(name: string, filter?: string): Promise<string[]>;
}
//#endregion
//#region src/index.d.ts
/**
 * Provides high-performance caching capabilities for Alepha applications with configurable TTL and multiple storage backends.
 *
 * The cache module enables declarative caching through the `$cache` descriptor, allowing you to cache method results,
 * API responses, or computed values with automatic invalidation and type safety. It supports both in-memory and
 * persistent storage backends for different performance and durability requirements.
 *
 * @see {@link $cache}
 * @see {@link CacheProvider}
 * @module alepha.cache
 */
declare const AlephaCache: _alepha_core0.Service<_alepha_core0.Module>;
//# sourceMappingURL=index.d.ts.map

//#endregion
export { $cache, AlephaCache, CacheDescriptor, CacheDescriptorFn, CacheDescriptorOptions, CacheProvider, MemoryCacheProvider };
//# sourceMappingURL=index.d.ts.map