Class: DurableHuggingfaceHub::Types::HFCacheInfo

Inherits:
Struct
  • Object
show all
Includes:
Loadable
Defined in:
lib/durable_huggingface_hub/types/cache_info.rb

Overview

Comprehensive cache information.

Contains information about the entire cache directory including all repositories.

Examples:

cache_info = HFCacheInfo.new(
  cache_dir: Pathname.new("/cache"),
  repos: [repo_info1, repo_info2],
  size: 2097152
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cache_dirPathname (readonly)

Path to the cache directory

Returns:

  • (Pathname)


227
# File 'lib/durable_huggingface_hub/types/cache_info.rb', line 227

attribute :cache_dir, Types::PathnameType

#reposArray<CachedRepoInfo> (readonly)

List of cached repositories

Returns:



232
# File 'lib/durable_huggingface_hub/types/cache_info.rb', line 232

attribute :repos, Types::Array.of(CachedRepoInfo)

#sizeInteger (readonly)

Total size of the cache in bytes

Returns:

  • (Integer)


237
# File 'lib/durable_huggingface_hub/types/cache_info.rb', line 237

attribute :size, Types::Integer

Instance Method Details

#file_countInteger

Total number of files across all repositories and revisions.

Returns:

  • (Integer)

    Total file count



272
273
274
# File 'lib/durable_huggingface_hub/types/cache_info.rb', line 272

def file_count
  repos.sum(&:file_count)
end

#repo_countInteger

Number of repositories in the cache.

Returns:

  • (Integer)

    Repository count



258
259
260
# File 'lib/durable_huggingface_hub/types/cache_info.rb', line 258

def repo_count
  repos.length
end

#repos_by_last_accessedArray<CachedRepoInfo>

Get repositories sorted by last accessed time (most recent first).

Returns:



286
287
288
# File 'lib/durable_huggingface_hub/types/cache_info.rb', line 286

def repos_by_last_accessed
  repos.compact.sort_by { |repo| repo.last_accessed || Time.at(0) }.reverse
end

#repos_by_last_modifiedArray<CachedRepoInfo>

Get repositories sorted by last modified time (most recent first).

Returns:

  • (Array<CachedRepoInfo>)

    Repositories sorted by modification time



293
294
295
# File 'lib/durable_huggingface_hub/types/cache_info.rb', line 293

def repos_by_last_modified
  repos.compact.sort_by { |repo| repo.last_modified || Time.at(0) }.reverse
end

#repos_by_sizeArray<CachedRepoInfo>

Get repositories sorted by size (largest first).

Returns:



279
280
281
# File 'lib/durable_huggingface_hub/types/cache_info.rb', line 279

def repos_by_size
  repos.sort_by { |repo| -repo.size }
end

#revision_countInteger

Total number of revisions across all repositories.

Returns:

  • (Integer)

    Total revision count



265
266
267
# File 'lib/durable_huggingface_hub/types/cache_info.rb', line 265

def revision_count
  repos.sum(&:revision_count)
end

#size_strString

Human-readable size string.

Returns:

  • (String)

    Size formatted as human-readable string



242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/durable_huggingface_hub/types/cache_info.rb', line 242

def size_str
  units = ["B", "KB", "MB", "GB", "TB"]
  size = self.size.to_f
  unit_index = 0

  while size >= 1024 && unit_index < units.length - 1
    size /= 1024.0
    unit_index += 1
  end

  format("%.2f %s", size, units[unit_index])
end