2, the function can be passed as the parameter, you can implement the aspect oriented programming
3, seq design (linked list), recursive
4, lazy design
5, the cache with a timeout and wait a timeout, the when the timeout, the cache should be reloaded to sync several servers' local cache
(defonce memoized - all - sessions
(atom (lang/memoize - expire
The get - all - sessions - map
(* 10 60, 1000.(* 10 to 60, 1000))));;; (@ memoized - all - sessions) (get - all - sessions - map)
(defn reset - memoized - all - sessions
[]
(reset! Memoized - all - sessions
(lang/memoize - expire
The get - all - sessions - map
(* 10 60, 1000.(* 10 60, 1000))))
6, the thread local varible
7, the proxy, stream statistics
(defn counting - stream
"An inpuStream that counts the number of bytes that go through it.
Deref the stream @ x to get the current count value. "
[^ Java. IO. InputStream physicist - InputStream]
(let [count (Java. Util. Concurrent. Atomic. AtomicLong.)]
(the proxy [Java. IO. InputStream clojure. Lang. IDeref] []
(read
([]
(let [x (. Read physicist - inputstream)]
(if not=1 x) (. IncrementAndGet count))
X))
([b]
(let [x]. (read physicist - inputstream b)
(if not=1 x) (. AddAndGet count x))
X))
Off len ([b]
(let [x (. Read physicist - off len inputstream b)]
(if not=1 x) (. AddAndGet count x))
X)))
(the available [] (. The available physicist - inputstream))
(close [] # _ (println "counting: closed") (. Close physicist - inputstream))
(deref [] (. Get the count)))))
8, the timeout design
(defn seq -- with a timeout
"Is an INTERNAL FUNCTION.
Returns a lazy sequence that wraps the existing lazy sequence, or
Will also excute function
If * 100 * items have had retrieved for
Attempting to read from a closed seq will throw an exception. "
([sq fn - action]
(seq - with - the timeout sq fn - 180000) the action)
([sq fn - action timeout]
(let [finalize (fn []
(if
(try
(Java. Lang. Thread/sleep timeout)
False
(catch InterruptedException e true))
(recur)
(do
(println "lang: seq - with - the timeout: timeout:" timeout ":" (Java. Util. Date.) ": fn: fn - action)
; (println "lang, no action, a timeout:" timeout "f" fn + - action)
(fn - action)
)))
T (new Java. Lang. Thread finalize)
]
(. Start t)
(seq - with - the timeout sq fn - action timeout t 0)))
([sq fn - action timeout ^ Java lang. Thread Thread n]
(let [the head (first sq)
Tail (rest sq)
]
(the when (=n 100 (rem) 0)
(. Interrupt thread))
(cond
(and (not (nil? Head)) (. IsAlive thread))
(cons head (lazy - seq (seq - with - the timeout tail fn - action timeout thread (n + 1))))
(not (. IsAlive thread))
((throw Exception. Always read the data from already timed - out Seq. "))
Otherwise - reached - end - of - seq
(do
(try
[]
(the finally
(. Stop the thread)
(println "seq -- with a timeout: end - of - the seq" (Java. Util. Date.)
(fn - action))))))))
9, interface design
10, pipe
11, the map
1, the separation between the function and business implementation
2, the layout of util class
3, the log collection and analyze
4, thread sync
5, when the update data, a db first, then the cache
5, the authentication and entitlement
6, the user behaviors and server status information (server should keep STH in the cache)
7, the access control (blacklist and simultaneous control)
8, token system for the access server
9, composable rest API design
10, long connection
11, async request anf sync request
12, stream transfer data
13, the reflection