• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10/apache-793/httpd/modules/ldap/

Lines Matching +defs:url +defs:cache

18  * util_ldap_cache_mgr.c: LDAP cache manager things
79 void util_ald_free(util_ald_cache_t *cache, const void *ptr)
82 if (cache->rmm_addr) {
85 apr_rmm_free(cache->rmm_addr, apr_rmm_offset_get(cache->rmm_addr, (void *)ptr));
98 void *util_ald_alloc(util_ald_cache_t *cache, unsigned long size)
103 if (cache->rmm_addr) {
105 apr_rmm_off_t block = apr_rmm_calloc(cache->rmm_addr, size);
106 return block ? (void *)apr_rmm_addr_get(cache->rmm_addr, block) : NULL;
117 const char *util_ald_strdup(util_ald_cache_t *cache, const char *s)
120 if (cache->rmm_addr) {
122 apr_rmm_off_t block = apr_rmm_calloc(cache->rmm_addr, strlen(s)+1);
123 char *buf = block ? (char *)apr_rmm_addr_get(cache->rmm_addr, block) : NULL;
145 util_compare_subgroup_t *util_ald_sgl_dup(util_ald_cache_t *cache, util_compare_subgroup_t *sgl_in)
154 sgl_out = (util_compare_subgroup_t *) util_ald_alloc(cache, sizeof(util_compare_subgroup_t));
156 sgl_out->subgroupDNs = util_ald_alloc(cache, sizeof(char *) * sgl_in->len);
159 sgl_out->subgroupDNs[i] = util_ald_strdup(cache, sgl_in->subgroupDNs[i]);
163 util_ald_free(cache, sgl_out->subgroupDNs[i]);
165 util_ald_free(cache, sgl_out->subgroupDNs);
166 util_ald_free(cache, sgl_out);
184 void util_ald_sgl_free(util_ald_cache_t *cache, util_compare_subgroup_t **sgl)
192 util_ald_free(cache, (*sgl)->subgroupDNs[i]);
194 util_ald_free(cache, *sgl);
227 Purges a cache that has gotten full. We keep track of the time that we
228 added the entry that made the cache 3/4 full, then delete all entries
232 void util_ald_cache_purge(util_ald_cache_t *cache)
238 if (!cache)
241 cache->last_purge = apr_time_now();
242 cache->npurged = 0;
243 cache->numpurges++;
245 for (i=0; i < cache->size; ++i) {
246 pp = cache->nodes + i;
249 if (p->add_time < cache->marktime) {
251 (*cache->free)(cache, p->payload);
252 util_ald_free(cache, p);
253 cache->numentries--;
254 cache->npurged++;
265 cache->avg_purgetime =
266 ((t - cache->last_purge) + (cache->avg_purgetime * (cache->numpurges-1))) /
267 cache->numpurges;
274 util_url_node_t *util_ald_create_caches(util_ldap_state_t *st, const char *url)
311 curl.url = url;
328 void * (*copyfunc)(util_ald_cache_t *cache, void *),
329 void (*freefunc)(util_ald_cache_t *cache, void *),
330 void (*displayfunc)(request_rec *r, util_ald_cache_t *cache, void *))
332 util_ald_cache_t *cache;
343 cache = (util_ald_cache_t *)calloc(sizeof(util_ald_cache_t), 1);
347 cache = block ? (util_ald_cache_t *)apr_rmm_addr_get(st->cache_rmm, block) : NULL;
350 cache = (util_ald_cache_t *)calloc(sizeof(util_ald_cache_t), 1);
352 if (!cache)
356 cache->rmm_addr = st->cache_rmm;
357 cache->shm_addr = st->cache_shm;
359 cache->maxentries = cache_size;
360 cache->numentries = 0;
361 cache->size = cache_size / 3;
362 if (cache->size < 64) cache->size = 64;
363 for (i = 0; primes[i] && primes[i] < cache->size; ++i) ;
364 cache->size = primes[i]? primes[i] : primes[i-1];
366 cache->nodes = (util_cache_node_t **)util_ald_alloc(cache, cache->size * sizeof(util_cache_node_t *));
367 if (!cache->nodes) {
368 /* This frees cache in the right way even if !APR_HAS_SHARED_MEMORY or !st->cache_rmm */
369 util_ald_free(cache, cache);
373 for (i=0; i < cache->size; ++i)
374 cache->nodes[i] = NULL;
376 cache->hash = hashfunc;
377 cache->compare = comparefunc;
378 cache->copy = copyfunc;
379 cache->free = freefunc;
380 cache->display = displayfunc;
382 cache->fullmark = cache->maxentries / 4 * 3;
383 cache->marktime = 0;
384 cache->avg_purgetime = 0.0;
385 cache->numpurges = 0;
386 cache->last_purge = 0;
387 cache->npurged = 0;
389 cache->fetches = 0;
390 cache->hits = 0;
391 cache->inserts = 0;
392 cache->removes = 0;
394 return cache;
397 void util_ald_destroy_cache(util_ald_cache_t *cache)
402 if (cache == NULL)
405 for (i = 0; i < cache->size; ++i) {
406 p = cache->nodes[i];
410 (*cache->free)(cache, p->payload);
411 util_ald_free(cache, p);
415 util_ald_free(cache, cache->nodes);
416 util_ald_free(cache, cache);
419 void *util_ald_cache_fetch(util_ald_cache_t *cache, void *payload)
424 if (cache == NULL)
427 cache->fetches++;
429 hashval = (*cache->hash)(payload) % cache->size;
431 for (p = cache->nodes[hashval];
432 p && !(*cache->compare)(p->payload, payload);
436 cache->hits++;
445 * Insert an item into the cache.
448 void *util_ald_cache_insert(util_ald_cache_t *cache, void *payload)
455 if (cache == NULL || payload == NULL) {
460 if (cache->numentries >= cache->maxentries) {
461 util_ald_cache_purge(cache);
462 if (cache->numentries >= cache->maxentries) {
465 "Purge of LDAP cache failed");
470 node = (util_cache_node_t *)util_ald_alloc(cache,
474 * XXX: The cache management should be rewritten to work
480 if (cache->numentries < cache->fullmark) {
486 cache->marktime = apr_time_now();
488 util_ald_cache_purge(cache);
489 node = (util_cache_node_t *)util_ald_alloc(cache,
493 "Could not allocate memory for LDAP cache entry");
499 tmp_payload = (*cache->copy)(cache, payload);
502 * XXX: The cache management should be rewritten to work
508 if (cache->numentries < cache->fullmark) {
514 cache->marktime = apr_time_now();
516 util_ald_cache_purge(cache);
517 tmp_payload = (*cache->copy)(cache, payload);
520 "Could not allocate memory for LDAP cache value");
521 util_ald_free(cache, node);
528 cache->inserts++;
529 hashval = (*cache->hash)(payload) % cache->size;
532 node->next = cache->nodes[hashval];
533 cache->nodes[hashval] = node;
538 if (++cache->numentries == cache->fullmark) {
539 cache->marktime=apr_time_now();
545 void util_ald_cache_remove(util_ald_cache_t *cache, void *payload)
550 if (cache == NULL)
553 cache->removes++;
554 hashval = (*cache->hash)(payload) % cache->size;
555 for (p = cache->nodes[hashval], q=NULL;
556 p && !(*cache->compare)(p->payload, payload);
567 cache->nodes[hashval] = p->next;
573 (*cache->free)(cache, p->payload);
574 util_ald_free(cache, p);
575 cache->numentries--;
578 char *util_ald_cache_display_stats(request_rec *r, util_ald_cache_t *cache, char *name, char *id)
588 if (cache == NULL) {
592 for (i=0; i < cache->size; ++i) {
593 if (cache->nodes[i] != NULL) {
595 for (n = cache->nodes[i];
624 cache->numentries,
625 (double)cache->numentries / (double)cache->maxentries * 100.0,
627 cache->hits,
628 cache->fetches,
629 (cache->fetches > 0 ? (double)(cache->hits) / (double)(cache->fetches) * 100.0 : 100.0),
630 cache->inserts,
631 cache->removes);
633 if (cache->numpurges) {
636 apr_ctime(str_ctime, cache->last_purge);
642 cache->numpurges,
651 buf = apr_psprintf(p, "%s<td align='right'>%.2gms</td>\n</tr>", buf, cache->avg_purgetime);
661 char *argfmt = "cache=%s&id=%d&off=%d";
662 char *scanfmt = "cache=%4s&id=%u&off=%u%1s";
685 buf = (char*)n->url;
855 t1 = apr_psprintf(pool, "%s (Searches)", n->url);
856 t2 = apr_psprintf(pool, "%s (Compares)", n->url);
857 t3 = apr_psprintf(pool, "%s (DNCompares)", n->url);