2
lein new caching

然后我进入并像这样编辑我的 project.clj 文件。

(defproject caching "1.0.0-SNAPSHOT"
  :description "FIXME: write description"
  :dependencies [[org.clojure/clojure "1.3.0"]
                 [org.clojure/core.cache "0.5.0"]]
  :plugins [[lein-swank "1.4.3"]])

我执行:

lein repl

依赖关系被拉出来,一切都很好。

然后,受https://github.com/clojure/core.cache/wiki/LRU上的示例文档的启发,我使用以下内容编辑 core.clj

(ns caching.core
  (:require [clojure.core.cache :as cache]))

(cache/lru-cache-factory {} :limit 2)

并在编译 core.clj 时返回以下错误。所以......我做错了什么?有没有人让它正常工作?

Wrong number of args (3) passed to: cache$lru-cache-factory
  [Thrown class clojure.lang.ArityException]

Restarts:
 0: [QUIT] Quit to the SLIME top level

Backtrace:
  0:        AFn.java:437 clojure.lang.AFn.throwArity
  1:         AFn.java:47 clojure.lang.AFn.invoke
  2:    NO_SOURCE_FILE:1 caching.core/eval2247
  3:  Compiler.java:6465 clojure.lang.Compiler.eval
  4:  Compiler.java:6431 clojure.lang.Compiler.eval
  5:       core.clj:2795 clojure.core/eval
  6:        core.clj:532 swank.core/eval782[fn]
  7:    MultiFn.java:163 clojure.lang.MultiFn.invoke
  8:        basic.clj:54 swank.commands.basic/eval-region
  9:        basic.clj:44 swank.commands.basic/eval-region
 10:        basic.clj:73 swank.commands.basic/eval968[fn]
 11:        Var.java:401 clojure.lang.Var.invoke
 12:    (Unknown Source) caching.core/eval2245
 13:  Compiler.java:6465 clojure.lang.Compiler.eval
 14:  Compiler.java:6431 clojure.lang.Compiler.eval
 15:       core.clj:2795 clojure.core/eval
 16:        core.clj:100 swank.core/eval-in-emacs-package
 17:        core.clj:256 swank.core/eval-for-emacs
 18:        Var.java:409 clojure.lang.Var.invoke
 19:        AFn.java:167 clojure.lang.AFn.applyToHelper
 20:        Var.java:518 clojure.lang.Var.applyTo
 21:        core.clj:600 clojure.core/apply
 22:        core.clj:107 swank.core/eval-from-control
 23:        core.clj:330 swank.core/spawn-worker-thread[fn]
 24:        AFn.java:159 clojure.lang.AFn.applyToHelper
 25:        AFn.java:151 clojure.lang.AFn.applyTo
 26:        core.clj:600 clojure.core/apply
 27:        core.clj:326 swank.core/spawn-worker-thread[fn]
 28:     RestFn.java:397 clojure.lang.RestFn.invoke
 29:         AFn.java:24 clojure.lang.AFn.run
 30:     Thread.java:662 java.lang.Thread.run
4

2 回答 2

4

core.cache 的 0.5.0 版似乎lru-cache-factory有不同的 args 列表。

这是提交a052bb568a1ca84b73ffda0bd252f01c5fa310aa的差异副本

-  [limit base]
+  [base & {limit :limit :or {limit 32}}]

尝试使用 core.cache 的 0.6.0-SNAPSHOT 以遵循教程。

于 2012-05-18T17:14:58.270 回答
1

如果您想继续依赖 0.5.0,您可以将代码更改为如下所示:

(ns caching.core
  (:require [clojure.core.cache :as cache]))

(cache/lru-cache-factory 2 {})
于 2012-05-22T16:04:21.657 回答