示例#1
0
        private IScalar LoadWithCache(string document, IServerProcess process)
        {
            IScalar result = null;

            lock (Cache)
            {
                uint cRC32 = Cache.GetCRC32(document);
                if (cRC32 > 0)
                {
                    try
                    {
                        result = LoadFromCache(document, process);
                    }
                    catch
                    {
                        result = null;
                        cRC32  = 0;
                    }
                }

                using
                (
                    DAE.Runtime.Data.Row row = (DAE.Runtime.Data.Row)process.Evaluate
                                               (
                        String.Format
                        (
                            "LoadIfNecessary('{0}', {1})",
                            document.Replace("'", "''"),
                            ((int)cRC32).ToString()
                        ),
                        null
                                               )
                )

                    if (!(bool)row["CRCMatches"])
                    {
                        using (DAE.Runtime.Data.Scalar value = row.GetValue("Value") as DAE.Runtime.Data.Scalar)
                        {
                            SaveToCache(document, process, value, (uint)(int)row["ActualCRC32"]);
                            result = (DAE.Runtime.Data.Scalar)value.Copy();
                        }
                    }
            }

            return(result);
        }
示例#2
0
        private IScalar InternalRequest(string document, IServerProcess process)
        {
            bool isImageRequest = false;

            if (ImageCache != null)
            {
                isImageRequest = IsImageRequest(document);
                if (isImageRequest)
                {
                    lock (ImageCache)
                    {
                        byte[] data;
                        if (ImageCache.TryGetValue(document, out data))
                        {
                            return(new Scalar(process.ValueManager, process.DataTypes.SystemGraphic, data));
                        }
                    }
                }
            }

            IScalar result;

            if (Cache != null)
            {
                result = LoadWithCache(document, process);
            }
            else
            {
                result = (IScalar)process.Evaluate(document, null);
            }

            if (isImageRequest)
            {
                SaveToImageCache(document, process, result);
            }

            return(result);
        }