예제 #1
0
 public static CommonCache GetInstance()
 {
     if (_instance == null)
     {
         _instance = new CommonCache();
     }
     return(_instance);
 }
예제 #2
0
        protected override void OnReceivedRequest(HttpRequest Request)
        {
            // Show HTTP request content
            Console.WriteLine(Request);

            // Handle user api service
            if (SendResponseAsync(ServiceHandler.ServiceHandler.GetInstance().RoutineHandler(Request, Response)) != true)
            {
                // Process HTTP request methods
                switch (Request.Method)
                {
                case "HEAD":
                {
                    SendResponseAsync(Response.MakeHeadResponse());
                }
                break;

                case "GET":
                {
                    // Get the cache value
                    string cache;
                    if (CommonCache.GetInstance().GetCache(Request.Url, out cache))
                    {
                        // Response with the cache value
                        SendResponseAsync(Response.MakeGetResponse(cache));
                    }
                    else
                    {
                        SendResponseAsync(Response.MakeErrorResponse("Required cache value was not found for the key: " + Request.Url));
                    }
                }
                break;

                case "POST":
                {
                    // Set the cache value
                    CommonCache.GetInstance().SetCache(Request.Url, Request.Body);
                    // Response with the cache value
                    SendResponseAsync(Response.MakeOkResponse());
                }
                break;

                case "PUT":
                {
                    // Set the cache value
                    CommonCache.GetInstance().SetCache(Request.Url, Request.Body);
                    // Response with the cache value
                    SendResponseAsync(Response.MakeOkResponse());
                }
                break;

                case "DELETE":
                {
                    // Delete the cache value
                    string cache;
                    if (CommonCache.GetInstance().DeleteCache(Request.Url, out cache))
                    {
                        // Response with the cache value
                        SendResponseAsync(Response.MakeGetResponse(cache));
                    }
                    else
                    {
                        SendResponseAsync(Response.MakeErrorResponse("Deleted cache value was not found for the key: " + Request.Url));
                    }
                }
                break;

                case "OPTIONS":
                {
                    SendResponseAsync(Response.MakeOptionsResponse());
                }
                break;

                case "TRACE":
                {
                    SendResponseAsync(Response.MakeTraceResponse(Request.Cache.Data));
                }
                break;

                default:
                {
                    SendResponseAsync(Response.MakeErrorResponse("Unsupported HTTP method: " + Request.Method));
                }
                break;
                }
            }
        }