Deno द्वारा संग्रहीत /tmp/deno_cache में क्या संग्रहीत है, यह जानने की उत्सुकता है

17 min

language: ja bn en es hi pt ru zh-cn zh-tw

नमस्ते, मैं अक्षम हूँ।
पिछले लेख में, मुझे पता चला कि /tmp/deno_cache में कैश संग्रहीत है, लेकिन मुझे यह जानने की उत्सुकता हुई कि क्या संग्रहीत है, इसलिए मैंने इसे देखा।

SQLite में संग्रहीत

सबसे पहले, हम /tmp/deno_cache पर जाने का प्रयास करते हैं।

cd /tmp/deno_cache
ls
7b52928d182b91e3d058c899022fc32b63d560748054c3143d70a24863f0f2ba

cd 7b52928d182b91e3d058c899022fc32b63d560748054c3143d70a24863f0f2ba
ls -la
कुल 120
drwxrwxr-x 3 haturatu haturatu  4096 10月 10 21:58 .
drwxrwxr-x 3 haturatu haturatu  4096 10月 10 21:58 ..
drwxrwxr-x 3 haturatu haturatu  4096 10月 10 21:58 1
-rw-r--r-- 1 haturatu haturatu  4096 10月 10 21:58 cache_metadata.db
-rw-r--r-- 1 haturatu haturatu 32768 10月 10 22:02 cache_metadata.db-shm
-rw-r--r-- 1 haturatu haturatu 70072 10月 10 22:02 cache_metadata.db-wal

ऐसा लगता है कि यह SQLite में संग्रहीत है। तो चलिए कनेक्ट करते हैं।

sqlite> .tables
cache_storage          request_response_list
sqlite> select * from cache_storage;
1|lume_remote_files
sqlite> select * from request_response_list;
1|1|https://cdn.jsdelivr.net/npm/svg2png-wasm@1.4.1/svg2png_wasm_bg.wasm||access-control-allow-origin
*
access-control-expose-headers
*
timing-allow-origin
*
cache-control
public, max-age=31536000, s-maxage=31536000, immutable
cross-origin-resource-policy
cross-origin
~~省略~~~
max-age=31536000; includeSubDomains; preload
x-content-type-options
nosniff
server
cloudflare
|200|OK|5f1e6f823db55b21ff1e048860bbbce7b104fe57fa3a4449ce36989784625f32|1728565376
sqlite>

तो, आइए deno_cache/01_cache.js से गहराई से देखते हैं

alleycat:[haturatu]:~/git/deno/ext/cache$ ls -la
कुल 60
drwxr-xr-x  2 haturatu haturatu  4096 10月 12 18:16 .
drwxr-xr-x 24 haturatu haturatu  4096 10月 12 18:16 ..
-rw-r--r--  1 haturatu haturatu  9048 10月 12 18:16 01_cache.js
-rw-r--r--  1 haturatu haturatu   491 10月 12 18:16 Cargo.toml
-rw-r--r--  1 haturatu haturatu  1043 10月 12 18:16 README.md
-rw-r--r--  1 haturatu haturatu  2042 10月 12 18:16 lib.deno_cache.d.ts
-rw-r--r--  1 haturatu haturatu  9827 10月 12 18:16 lib.rs
-rw-r--r--  1 haturatu haturatu 12666 10月 12 18:16 sqlite.rs
alleycat:[haturatu]:~/git/deno/ext/cache$ cat Cargo.toml 
# Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

[package]
name = "deno_cache"
version = "0.103.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
readme = "README.md"
repository.workspace = true
description = "Implementation of Cache API for Deno"

[lib]
path = "lib.rs"

[dependencies]
async-trait.workspace = true
deno_core.workspace = true
rusqlite.workspace = true
serde.workspace = true
sha2.workspace = true
tokio.workspace = true

alleycat:[haturatu]:~/git/deno/ext/cache$ grep "tmp" ./*
alleycat:[haturatu]:~/git/deno/ext/cache$ grep "deno_cache" ./*
./Cargo.toml:name = "deno_cache"
./README.md:# deno_cache
./lib.rs:deno_core::extension!(deno_cache,

alleycat:[haturatu]:~/git/deno/ext/cache$ cat lib.rs 
~~~
deno_core::extension!(deno_cache,
  deps = [ deno_webidl, deno_web, deno_url, deno_fetch ],
  parameters=[CA: Cache],
  ops = [
    op_cache_storage_open<CA>,
    op_cache_storage_has<CA>,
    op_cache_storage_delete<CA>,
    op_cache_put<CA>,
    op_cache_match<CA>,
    op_cache_delete<CA>,
  ],
  esm = [ "01_cache.js" ],
  options = {
    maybe_create_cache: Option<CreateCache<CA>>,
  },
  state = |state, options| {
    if let Some(create_cache) = options.maybe_create_cache {
      state.put(create_cache);
    }
  },
);
~~~

alleycat:[haturatu]:~/git/deno/ext/cache$ grep " op_cache_storage" ./*
./01_cache.js:  op_cache_storage_delete,
./01_cache.js:  op_cache_storage_has,
./01_cache.js:  op_cache_storage_open,
./01_cache.js:    const cacheId = await op_cache_storage_open(cacheName);
./01_cache.js:    return await op_cache_storage_has(cacheName);
./01_cache.js:    return await op_cache_storage_delete(cacheName);
./lib.rs:    op_cache_storage_open<CA>,
./lib.rs:    op_cache_storage_has<CA>,
./lib.rs:    op_cache_storage_delete<CA>,
./lib.rs:pub async fn op_cache_storage_open<CA>(
./lib.rs:pub async fn op_cache_storage_has<CA>(
./lib.rs:pub async fn op_cache_storage_delete<CA>(

alleycat:[haturatu]:~/git/deno/ext/cache$ grep "cacheName" ./*
./01_cache.js:  async open(cacheName) {
./01_cache.js:    cacheName = webidl.converters["DOMString"](cacheName, prefix, "Argument 1");
./01_cache.js:    const cacheId = await op_cache_storage_open(cacheName);
./01_cache.js:  async has(cacheName) {
./01_cache.js:    cacheName = webidl.converters["DOMString"](cacheName, prefix, "Argument 1");
./01_cache.js:    return await op_cache_storage_has(cacheName);
./01_cache.js:  async delete(cacheName) {
./01_cache.js:    cacheName = webidl.converters["DOMString"](cacheName, prefix, "Argument 1");
./01_cache.js:    return await op_cache_storage_delete(cacheName);
./lib.deno_cache.d.ts:  open(cacheName: string): Promise<Cache>;
./lib.deno_cache.d.ts:  has(cacheName: string): Promise<boolean>;
./lib.deno_cache.d.ts:  delete(cacheName: string): Promise<boolean>;

हम sqlite.rs देखते हैं।

alleycat:[haturatu]:~/git/deno/ext/cache$ grep "cache_storage_dir" ./*
./sqlite.rs:  pub cache_storage_dir: PathBuf,
./sqlite.rs:  pub fn new(cache_storage_dir: PathBuf) -> Self {
./sqlite.rs:      std::fs::create_dir_all(&cache_storage_dir)
./sqlite.rs:      let path = cache_storage_dir.join("cache_metadata.db");
./sqlite.rs:        cache_storage_dir,
./sqlite.rs:    let cache_storage_dir = self.cache_storage_dir.clone();
./sqlite.rs:      let responses_dir = get_responses_dir(cache_storage_dir, cache_id);
./sqlite.rs:    let cache_storage_dir = self.cache_storage_dir.clone();
./sqlite.rs:        let cache_dir = cache_storage_dir.join(cache_id.to_string());
./sqlite.rs:    let cache_storage_dir = self.cache_storage_dir.clone();
./sqlite.rs:        get_responses_dir(cache_storage_dir, request_response.cache_id);
./sqlite.rs:    let cache_storage_dir = self.cache_storage_dir.clone();
./sqlite.rs:          get_responses_dir(cache_storage_dir, request.cache_id)
./sqlite.rs:fn get_responses_dir(cache_storage_dir: PathBuf, cache_id: i64) -> PathBuf {
./sqlite.rs:  cache_storage_dir

alleycat:[haturatu]:~/git/deno/ext/cache$ head -5 sqlite.rs 
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use std::borrow::Cow;
use std::path::PathBuf;
use std::pin::Pin;
use std::rc::Rc;

alleycat:[haturatu]:~/git/deno$ grep "PathBuf" ./*/* 2>/dev/null | grep -v use
./cli/build.rs:    let op_crate_libs = state.borrow::<HashMap<&str, PathBuf>>();
./cli/build.rs:    let path_dts = state.borrow::<PathBuf>();
./cli/build.rs:          PathBuf::from(op_crate_lib).canonicalize()?
./cli/build.rs:      op_crate_libs: HashMap<&'static str, PathBuf>,
./cli/build.rs:      path_dts: PathBuf,
./cli/build.rs:  pub fn create_compiler_snapshot(snapshot_path: PathBuf, cwd: &Path) {
./cli/build.rs:      PathBuf::from(env::var_os("OUT_DIR").unwrap())
~~~
alleycat:[haturatu]:~/git/deno$ cd ./ext/cache/
alleycat:[haturatu]:~/git/deno/ext/cache$ grep let ./* | grep dir
./sqlite.rs:      let path = cache_storage_dir.join("cache_metadata.db");
./sqlite.rs:    let cache_storage_dir = self.cache_storage_dir.clone();
./sqlite.rs:      let responses_dir = get_responses_dir(cache_storage_dir, cache_id);
./sqlite.rs:    let cache_storage_dir = self.cache_storage_dir.clone();
./sqlite.rs:        let cache_dir = cache_storage_dir.join(cache_id.to_string());
./sqlite.rs:    let cache_storage_dir = self.cache_storage_dir.clone();
./sqlite.rs:      let responses_dir =
./sqlite.rs:      let response_path = responses_dir.join(&body_key);
./sqlite.rs:    let cache_storage_dir = self.cache_storage_dir.clone();

alleycat:[haturatu]:~/git/deno/ext/cache$ vim ./sqlite.rs
alleycat:[haturatu]:~/git/deno/ext/cache$ cat ./sqlite.rs
~~~
use std::path::PathBuf;
~~~
#[derive(Clone)]
pub struct SqliteBackedCache {
  pub connection: Arc<Mutex<Connection>>,
  pub cache_storage_dir: PathBuf,
}
~~~

PathBuf

आधिकारिक दस्तावेज़

alleycat:[haturatu]:~/git/deno/ext/cache$ cd -
alleycat:[haturatu]:~/git/deno$ grep "let mut" ./*/*/* | grep "PathBuf"
grep: ./cli/bench/fs: एक निर्देशिका है
grep: ./cli/bench/http: एक निर्देशिका है
grep: ./cli/bench/napi: एक निर्देशिका है
grep: ./cli/bench/stdio: एक निर्देशिका है
grep: ./cli/bench/testdata: एक निर्देशिका है
./cli/cache/disk_cache.rs:    let mut out = PathBuf::new();

ओह!

alleycat:[haturatu]:~/git/deno/cli/cache$ cd ./cli/cache/
alleycat:[haturatu]:~/git/deno/cli/cache$ ls -la
कुल 136
drwxr-xr-x  2 haturatu haturatu  4096 10月 12 18:16 .
drwxr-xr-x 15 haturatu haturatu  4096 10月 12 18:16 ..
-rw-r--r--  1 haturatu haturatu 17292 10月 12 18:16 cache_db.rs
-rw-r--r--  1 haturatu haturatu  3643 10月 12 18:16 caches.rs
-rw-r--r--  1 haturatu haturatu  5190 10月 12 18:16 check.rs
-rw-r--r--  1 haturatu haturatu  5668 10月 12 18:16 code_cache.rs
-rw-r--r--  1 haturatu haturatu  1090 10月 12 18:16 common.rs
-rw-r--r--  1 haturatu haturatu  8449 10月 12 18:16 deno_dir.rs
-rw-r--r--  1 haturatu haturatu  7647 10月 12 18:16 disk_cache.rs
-rw-r--r--  1 haturatu haturatu  7195 10月 12 18:16 emit.rs
-rw-r--r--  1 haturatu haturatu  4531 10月 12 18:16 fast_check.rs
-rw-r--r--  1 haturatu haturatu  8367 10月 12 18:16 incremental.rs
-rw-r--r--  1 haturatu haturatu 12142 10月 12 18:16 mod.rs
-rw-r--r--  1 haturatu haturatu  7796 10月 12 18:16 module_info.rs
-rw-r--r--  1 haturatu haturatu  4847 10月 12 18:16 node.rs
-rw-r--r--  1 haturatu haturatu  4567 10月 12 18:16 parsed_source.rs

alleycat:[haturatu]:~/git/deno/cli/cache$ vim disk_cache.rs 
~~~
impl DiskCache {
  /// `location` must be an absolute path.
  pub fn new(location: &Path) -> Self {
    assert!(location.is_absolute());
    Self {
      location: location.to_owned(),
    }
  }

  fn get_cache_filename(&self, url: &Url) -> Option<PathBuf> {
    let mut out = PathBuf::new();
~~~

alleycat:[haturatu]:~/git/deno/cli/cache$ grep "get_cache_filename" ./* | grep "let"
./disk_cache.rs:    let base = self.get_cache_filename(url)?;

मुझे कुछ हद तक समझ आ गया है कि किसे कहाँ से बुलाया जा रहा है।
वैसे, पिछली बार जो त्रुटि हुई थी, वह शायद कोई बग नहीं थी, बल्कि स्वामित्व बदलने का एक दुर्लभ पैटर्न था, उदाहरण के लिए,

which deno
/home/haturatu/.deno/bin/deno

जब ऐसा होता है, तो इस deno का निष्पादन उपयोगकर्ता haturatu होता है।
और, यदि इसे जानबूझकर किसी अन्य उपयोगकर्ता के अधिकारों के साथ निष्पादित किया जाता है, तो उत्पन्न /tmp/deno_cache अन्य उपयोगकर्ताओं के साथ टकराव का कारण बनेगा।
कई उपयोगकर्ताओं के बीच deno कमांड को निष्पादित नहीं किया जाना चाहिए (आवश्यक पैटर्न को छोड़कर), और मुझे लगता है कि यह उचित है।
यदि इसे सख्ती से किया जाए, तो deno उपयोगकर्ता बनाना और उसके साथ इंस्टॉल और निष्पादित करना शायद बेहतर होगा।

लेकिन अगर कुछ चिंताजनक है तो वह यह है

deno info करने पर /tmp/deno_cache का आउटपुट नहीं होना।

alleycat:[haturatu]:~/git/deno/ext/cache$ deno info
DENO_DIR location: /home/haturatu/.cache/deno
Remote modules cache: /home/haturatu/.cache/deno/deps
npm modules cache: /home/haturatu/.cache/deno/npm
Emitted modules cache: /home/haturatu/.cache/deno/gen
Language server registries cache: /home/haturatu/.cache/deno/registries
Origin storage: /home/haturatu/.cache/deno/location_data

यह मुझे थोड़ा उत्सुक कर गया, इसलिए मैंने इसे एक नोट के रूप में लिख लिया।
तो फिर।
फिर मिलेंगे।

Related Posts