From 023521fcb6713e1151a04e4358bb58695dd6e479 Mon Sep 17 00:00:00 2001 From: Florin Coras Date: Mon, 7 Feb 2022 16:24:43 -0800 Subject: http_static: cleanup file handler and cache Type: refactor Signed-off-by: Florin Coras Change-Id: I7aff3a02315f9f92039dd2e3af1cbd8312aec662 --- src/plugins/http_static/http_cache.h | 78 ++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/plugins/http_static/http_cache.h (limited to 'src/plugins/http_static/http_cache.h') diff --git a/src/plugins/http_static/http_cache.h b/src/plugins/http_static/http_cache.h new file mode 100644 index 00000000000..a89ed5e7e94 --- /dev/null +++ b/src/plugins/http_static/http_cache.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SRC_PLUGINS_HTTP_STATIC_HTTP_CACHE_H_ +#define SRC_PLUGINS_HTTP_STATIC_HTTP_CACHE_H_ + +#include + +typedef struct hss_cache_entry_ +{ + /** Name of the file */ + u8 *filename; + /** Contents of the file, as a u8 * vector */ + u8 *data; + /** Last time the cache entry was used */ + f64 last_used; + /** Cache LRU links */ + u32 next_index; + u32 prev_index; + /** Reference count, so we don't recycle while referenced */ + int inuse; +} hss_cache_entry_t; + +typedef struct hss_cache_ +{ + /** Unified file data cache pool */ + hss_cache_entry_t *cache_pool; + /** Hash table which maps file name to file data */ + BVT (clib_bihash) name_to_data; + + /** Session pool lock */ + clib_spinlock_t cache_lock; + + /** Current cache size */ + u64 cache_size; + /** Max cache size in bytes */ + u64 cache_limit; + /** Number of cache evictions */ + u64 cache_evictions; + + /** Cache LRU listheads */ + u32 first_index; + u32 last_index; + + u8 debug_level; +} hss_cache_t; + +u32 hss_cache_lookup_and_attach (hss_cache_t *hc, u8 *path, u8 **data, + u64 *data_len); +u32 hss_cache_add_and_attach (hss_cache_t *hc, u8 *path, u8 **data, + u64 *data_len); +void hss_cache_detach_entry (hss_cache_t *hc, u32 ce_index); +u32 hss_cache_clear (hss_cache_t *hc); +void hss_cache_init (hss_cache_t *hc, uword cache_size, u8 debug_level); + +u8 *format_hss_cache (u8 *s, va_list *args); + +#endif /* SRC_PLUGINS_HTTP_STATIC_HTTP_CACHE_H_ */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ -- cgit 1.2.3-korg